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!

sh command: display output on certain lines

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
Does anybody knows of an unix command to display output of a file on a certain lines?

For example, i want to copy lines 406-1933 of a file to another file. I can't think of a way to strip it out, does anybody know if unix can do it.

Thanks!
 
You could:

tail -(total no of lines in file - 405) filename > tempfile1
head -(lines in tempfile1 - 1527) tempfile1 > tempfile2

tempfile2 should contain the lines you want. You may have to play with the exact number of lines, but I hope this gives you an idea.
 
Thanks Ken.

But how you get the lines in between? saying line 406-1933.

Note that 1933 is greater than MAX_BYTES allowed.

Can this be done in plain unix?
 
try awk ...

think this should work, sorry not near a machine, as would need to try first.

try posting this question in the awk forum

martin
 
what's about sed?

sed -n '406,1933p' input.txt > output.txt

man sed

Chacal, Inc.[wavey]
 
Thanks Chacal,

Unfortunately, sed only allows up to max lines. on my machine, it only display the output up to 1122 lines. everything else got cut.
 
Pho,

what is your version of HP-UX?
I tried with HP-UX 11i, and the solutions given by Ken and Chacal worked.

I don't know about a parameter MAX_BYTES, or a line limit, could you tell us more about it?
(I remember having seen a similar limitation on an old SCO Unix system, looong ago, but it don't know if there was a workaround.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top