Computing.Net > Forums > Unix > remove top line in file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

remove top line in file

Reply to Message Icon

Name: Pete
Date: March 26, 2003 at 01:45:24 Pacific
OS: Linux
CPU/Ram: 512MB
Comment:

This may be a silly question but does anyone know how I can remove the top line of a file and save it to another file. Is there a command for this. Many thanks.




Sponsored Link
Ads by Google

Response Number 1
Name: Jimbo
Date: March 26, 2003 at 01:55:43 Pacific
Reply:

sed -n '1p' your_file > new_file

This will not alter your_file. It takes the first line of it and puts it in new_file.

-jim


0

Response Number 2
Name: pete
Date: March 26, 2003 at 03:58:10 Pacific
Reply:

Thanks Jim, I will try that out. Do you know any good books out that are good for learning how to write scripts on UNIX systems?

Pete


0

Response Number 3
Name: Jimbo
Date: March 26, 2003 at 04:01:40 Pacific
Reply:

I would recommend 'Shell programming by Example' by Ellie Quigley. bookpool.com has it, i believe.

-jim


0

Response Number 4
Name: Jimbo
Date: March 26, 2003 at 04:19:14 Pacific
Reply:

Correction, thats:

Unix Shells by example
by Ellie Quigley


-jim


0

Response Number 5
Name: WilliamRobertson
Date: March 26, 2003 at 04:40:24 Pacific
Reply:

Or for variety,
head -n1 yourfile.dat > newfile.dat

Another great book is "Learning the Korn Shell" by Bill Rosenblatt (O'Reilly). What I like about it is the way it describes how things work rather than just listing syntax and examples. It has quite a bit about using the command line and customising your environment as well. There are a lot of convenient shortcuts that people often don't know about.

Also if you're going to be spending any time working with Unix, get the O'Reilly book on the vi editor and work through it from cover to cover (it's not that long). I did this about 10 years back (we had a slow patch at work) and I'm so glad I did. vi is a terrific editor once you get to know it (and the regular expression syntax is pretty much the same as grep/sed/awk, Perl and JavaScript).


0

Related Posts

See More



Response Number 6
Name: Jimbo
Date: March 26, 2003 at 04:55:23 Pacific
Reply:

Ditto on the Oreilly Korn shell book. Also one of my favorites.

-jim


0

Response Number 7
Name: Pete
Date: March 26, 2003 at 18:27:21 Pacific
Reply:

Thank you all for helping me out.

Pete


0

Response Number 8
Name: Pete
Date: March 26, 2003 at 18:34:35 Pacific
Reply:

I need more help on removing the first line of my file. I have tried both suggestions but both of them seems to extract the 1st line of my old file and places to a new file. I didn't exactly want that. What I wanted to do is to remove the 1st line in the old file then copy the remaining to the new file or make a copy of the original file then remove the 1st line or 1st couple line from the new file. For example, file 1 contains:
line 1
line 2
line 3
line 4

File 2 should be:
line 2
line 3
line 4

Any suggestion on this? Many thanks.


0

Response Number 9
Name: Jimbo
Date: March 26, 2003 at 21:53:23 Pacific
Reply:

sed -n '2,$p' file > file2

-jim


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: remove top line in file

Removing a lines in a file www.computing.net/answers/unix/removing-a-lines-in-a-file/7453.html

Remove Last Word in File www.computing.net/answers/unix/remove-last-word-in-file/7535.html

script to remove some lines in all www.computing.net/answers/unix/script-to-remove-some-lines-in-all-/6195.html