Operating System - HP-UX
1832591 Members
3093 Online
110043 Solutions
New Discussion

Get rid of the first line of an output file

 
SOLVED
Go to solution
Simeon Harwood
Regular Advisor

Get rid of the first line of an output file

Morning all,
I've found an anoying problem with "tail".
I've got an output file that is more that 5000 lines long. This needs to be cleaned up to be used as a load for a database. I can clean up all the file as needed, but I need to get rid of the header info. Usually, I would do a
"wc -l" on the file, do a sum to take off say 1 or 2 lines, then do a "tail -n " on the file to get rid of it.
BUT "tail" seems to have a limit on it, and so dosen't report the whole file back to me.
Does anyone have a little trick up their sleeve to get round this please.

Thanks,
Sime.
You never had this problem with a pencil and paper!
6 REPLIES 6
Gavin Clarke
Trusted Contributor
Solution

Re: Get rid of the first line of an output file

Well you could use split then cat.

split -n 10000 filename
tail -9999 xxa > trimmedfile
cat trimmedfile xxb xxc xxd > filename

Or something like that, you may have to tailor it so that tail can cope.

Probably not the best solution, it's a thought though.
Simeon Harwood
Regular Advisor

Re: Get rid of the first line of an output file

Just realised that I can use: -
sed '1d'

I guess I need to wake up a bit......

You never had this problem with a pencil and paper!
Orhan Biyiklioglu
Respected Contributor

Re: Get rid of the first line of an output file

sed -n '2,$p' filename

will also print lines from 2 to the end of the file...
Gavin Clarke
Trusted Contributor

Re: Get rid of the first line of an output file

Attached Handy one-liners for SED, which I originally got from the forums. It might not be the latest version.

I hope you like it.
Fred Martin_1
Valued Contributor

Re: Get rid of the first line of an output file

sometimes i use awk for this, when the file is large and I don't trust tail.

Assume there are three header lines:

awk '{if(NR>3){print}}' filename
fmartin@applicatorssales.com
Sorrel G. Jakins
Valued Contributor

Re: Get rid of the first line of an output file

Thank you Gavin for that very handy file.