LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 09: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 09:34 PM.
 
Old 11-06-2013, 09:33 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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, 09: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



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 01:23 PM
Printing specific lines of a file using script. barunparichha Linux - Software 6 05-20-2009 12:31 AM
BASH Scripting - printing select lines in a file bullfrog1870 Linux - Newbie 16 11-08-2006 09:33 AM
Printing random lines of a file jrdioko Linux - Software 3 07-20-2006 09:00 AM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 02:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:49 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
Open Source Consulting | Domain Registration