Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a specific line number

Status
Not open for further replies.

BryanY

MIS
Aug 18, 2001
54
US
I want to pull the data from the second line of a file. How would a specify to do that?
 
Different ways:
awk 'NR==2{print;exit}' /path/to/input
sed '2{;p;q;}' /path/to/input
tail -n +2 /path/to/input | head -1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Or simply let the shell do it, korn shell in this case:

#!/bin/ksh

i=0
while read line
do
((i=$i+1))
(( $i == 2 )) && break
done < myfile

echo ${line}

Regards,

Ed
 
Not pretty but effective

head -2 /etc/hosts > /tmp/look.file|tail -1 /tmp/look.file

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top