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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print certain lines only ?

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
0
0
US
I want to know how I can print only certain lines in a file? Say, if I only want to redirect lines:

2, 3, 5, 7, and 14?

I know in sed you can only print a range like 2-15, but I want to redirect only certain lines. I cant fgrep or grep because there is never the same variables in the file. It is always different. Thanks, BeasteR
 
Try with:

awk 'NR==2||NR==3||NR==5||NR==7||NR==14' <file>

Yours, Mauro
 
Perfect, that is exactly what I was looking for! Thanks it works great!

BeasteR
 
You can also do this :

awk '&quot; &quot;NR&quot; &quot; ~ /[ 2 3 5 7 14 ]/' file

Regards

fcail
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top