1834391 Members
1545 Online
110066 Solutions
New Discussion

deleting lines ..

 
SOLVED
Go to solution
someone_4
Honored Contributor

deleting lines ..

Hey everyone ..
How would I delete the first and last lines of a file.The number of lines is always chaning too.

Thanks

Richard
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: deleting lines ..

Hi Richard:

Use 'sed'.

To delete the first line of a file, do:

# sed '1d' file.old > file.new

To delete the last line of a file:

# sed '$d' file.old > file.new

...JRF...
someone_4
Honored Contributor

Re: deleting lines ..

That wored great. But this is what I am having to do to delete both lines.

# sed '1d' file.old > file.new
then
# sed '$d' file.new > file1.new

But they leave the file.old and the file.new files there. I can always go and delete them.
But is there a way to do this with one command?

Richard



James R. Ferguson
Acclaimed Contributor

Re: deleting lines ..

Hi (again) Richard:

Try this:

# sed -e '1d' -e '$d' file.old > file.new
# mv file.new file.old

...JRF...
someone_4
Honored Contributor

Re: deleting lines ..

Thanks for your help ! That worked great !
I am going to order the awk and sed by oreilly. And learn a bit more about thoose tools.

Richard