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!

How to extract some lines from one file to output to another file 1

Status
Not open for further replies.

micotao

Programmer
Jun 16, 2004
33
CN
Hi,
If I want to extract the contents of one file, from its line 3 to its line 15( suppose it has 100 lines). Which commands can I use to function this?
I only know how to extract the first N lines from one file to output to another file, say:
head -16 somefile > otherfile
Thanks for your help!
I think sed/awk and some other commands can finish this function, but I don't know exactly. Can you please help?
Thanks.
 
sed -n 3,15p
awk 'NR==3, NR==15'

And the most speedy, the head -15 | tail +3 combination

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
Cheers, speed related updates to the above, only worth if processing much data.. head|tail is still faster:

awk 'FNR==3, FNR==15; FNR==15{exit}'
-> awk 'FNR==3, FNR==15 { print; if (FNR == 15) exit }'
sed -ne 3,15p -e 15Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top