LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trim first 10 lines out of a file (https://www.linuxquestions.org/questions/linux-newbie-8/trim-first-10-lines-out-of-a-file-682846/)

hattori.hanzo 11-12-2008 04:50 AM

Trim first 10 lines out of a file
 
How would one trim/cut the first 10 lines of a file.

I had a look at cut,head,tail and trim. are their any other commands to look at or techniques?

thanks.

anonobomber 11-12-2008 04:56 AM

awk '{if (NR!=10) {print}}' cut.me.file

H_TeXMeX_H 11-12-2008 05:22 AM

Try

Code:

sed '1,10d' infile > outfile

colucix 11-12-2008 05:34 AM

Or
Code:

awk 'NR>10' infile > outfile

pinniped 11-12-2008 05:34 AM

Dang, I was beaten to the 'awk' script.

Were you successful with 'tail'?

tail --lines=+10 myfile

The docs might give the impression that one of these would work:

tail -+10 myfile
tail +10 myfile

but unfortunately that isn't the case - you have to use '--lines='

colucix 11-12-2008 05:43 AM

Quote:

Originally Posted by pinniped (Post 3339304)
The docs might give the impression that one of these would work:

tail -+10 myfile
tail +10 myfile

but unfortunately that isn't the case - you have to use '--lines='

Yes. The syntax tail +N is considered obsolete and it is not valid on some systems, due to the recent POSIX specifications. You can always use this syntax by forcing the tail command to conform to an old POSIX version, for example:
Code:

env _POSIX2_VERSION=199209 tail +11 infile
should work on most systems. This defines an environment variable to force POSIX 1003.2-1992 specification. You can find this info in the coreutils manual or in the corresponding section of info coreutils.

Anyway, better to use the --lines option, as you suggested, or its short form:
Code:

tail -n +11 infile

hattori.hanzo 11-12-2008 07:48 AM

Thanks guys. I ended up using

Code:

sed '1,10d' infile > outfile
It is good to know about the other approaches too.

Cheers.

H_TeXMeX_H 11-12-2008 08:40 AM

There are so many ways to do it, it's hard to chose.

But now that I helped you, you have to craft me a sword ;)


All times are GMT -5. The time now is 08:16 AM.