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!

Get 2nd Line in File 1

Status
Not open for further replies.

jestrada101

Technical User
Mar 28, 2003
332
What would be a good unix command to get the 2nd line from a file?

Thanks
JE
 
head -2 file | tail -1

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Or the awk way:
awk 'NR==2{print;exit}' /path/to/file

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
or.... (amoung other possibilities):

sed -ne '2p' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hello Vlad.
Just a note: your sed solution will read the entire file.
 
ooops, sorry - thanks for the catch:

sed -e '2q;d' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top