LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-06-2013, 10:28 PM   #1
TRUNoise
Member
 
Registered: Apr 2013
Location: /home/
Distribution: Ubuntu 14.04
Posts: 50

Rep: Reputation: 7
Smile Printing different lines of a file from a script


As the title would refer, I need a script to be able to read different lines and display the contents of each line.

For example; file "prop"
Code:
3G
server.jar
would be required from a script along the lines of
Code:
echo "====[ $(pwd) ]=====" #show what server it is
echo "server will run with $(cat prop;line1) of memory" #obviously not going to actually work but thats the concept
echo "server will run with jar file $(cat prop;line2)" #same comment as before
Before anyone asks, the 3G part is the memory the server will be started with and (obviously) the server.jar file is the actual server, which is written in Java.

Hope it's doable.

Last edited by TRUNoise; 11-06-2013 at 10:34 PM.
 
Old 11-06-2013, 10:33 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

are you asking how to select line number n from a text file? If so, you can use sed. For example, to select the 2nd line of the file "prop", you could do:
Code:
sed -n -e '2 p' prop
HTH,

Evo2.
 
1 members found this post helpful.
Old 11-06-2013, 10:37 PM   #3
TRUNoise
Member
 
Registered: Apr 2013
Location: /home/
Distribution: Ubuntu 14.04
Posts: 50

Original Poster
Rep: Reputation: 7
Quote:
Originally Posted by evo2 View Post
Hi,

are you asking how to select line number n from a text file? If so, you can use sed. For example, to select the 2nd line of the file "prop", you could do:
Code:
sed -n -e '2 p' prop
HTH,

Evo2.
Much appreciated, exactly what I needed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[awk script] Help me delete lines in a file using script ? sieukid Programming 5 03-20-2012 02:23 PM
Printing specific lines of a file using script. barunparichha Linux - Software 6 05-20-2009 01:31 AM
BASH Scripting - printing select lines in a file bullfrog1870 Linux - Newbie 16 11-08-2006 10:33 AM
Printing random lines of a file jrdioko Linux - Software 3 07-20-2006 10:00 AM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 03:03 PM


All times are GMT -5. The time now is 04:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration