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!

Display Entire File Except for First 5 Lines 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

On a Sun Solaris 8 system how can I display the contents of a text file except for the first 5 lines?

The file size varies but is usually less than 300 lines. Ideally I will put this in a Bourne shell script.

Thanks,

Michael42
 
Try

tail +6 <filename>

or

awk 'NR>5' <filename>

HTH,

p5wizard
 
p5wizard,

Perfect! :)

Thanks for posting,

Michael42
 
One more related question on this please...

How can I display the contents of a text file except for the last 3 lines?

I have been playing with the head and tail commands but still don't quite have it.

Thanks,

Michael42
 
I don't think head or tail can do this "all but last three" without first reversing the file, tail +4, reversing again. (at least not on AIX)

awk can do:

awk '{
if (NR>3) print one;
one=two
two=three
three=$0
}' filename

This is a bad design - the 3 shouldn't be hardcoded, and then using an array would be better than three individual variables, but I guess you get the idea from this.


HTH,

p5wizard
 
Try...
[tt] awk -v n=3 'NR>n{print a[NR%n]}{a[NR%n]=$0}' file1[/tt]
 
I think that negative values for the -n option are only for GNU head. The OP has stated that he is using Sun Solaris 8 where this feature is not available.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top