LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-12-2008, 05:50 AM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Rep: Reputation: 15
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.
 
Old 11-12-2008, 05:56 AM   #2
anonobomber
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: Debian, Fedora, CentOS, FreeBSD, OpenSolaris
Posts: 138

Rep: Reputation: 16
awk '{if (NR!=10) {print}}' cut.me.file
 
Old 11-12-2008, 06:22 AM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
Try

Code:
sed '1,10d' infile > outfile
 
Old 11-12-2008, 06:34 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Or
Code:
awk 'NR>10' infile > outfile
 
Old 11-12-2008, 06:34 AM   #5
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
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='
 
Old 11-12-2008, 06:43 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by pinniped View Post
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

Last edited by colucix; 11-12-2008 at 06:54 AM. Reason: Added reference
 
Old 11-12-2008, 08:48 AM   #7
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Thanks guys. I ended up using

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

Cheers.
 
Old 11-12-2008, 09:40 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to trim some bytes off the end of a file onedingo Linux - Software 5 07-04-2007 07:13 PM
trim lines based on other file. hepburnenthorpe Linux - Newbie 1 04-02-2007 11:07 PM
Random file lines directed to a new file. In script an error. In command line no err leventis Programming 1 09-28-2006 08:16 AM
How To Trim A File fpfernando Programming 11 01-05-2006 09:04 AM
vim: mark end-of-line? trim blank lines? prell Linux - Software 3 09-21-2004 12:04 AM


All times are GMT -5. The time now is 05:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration