Computing.Net > Forums > Programming > sed remove lines from a 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.

sed remove lines from a file

Reply to Message Icon

Name: G Chen
Date: November 12, 2005 at 04:30:48 Pacific
OS: linux
CPU/Ram: 2.5g
Comment:

I'd like to clean a log file up by removing several lines for example:

LINE1
LINE2
LINE3
LINE4
LINE5

end result:

LINE2
LINE3
LINE5

Can anybody help?

gangchen



Sponsored Link
Ads by Google

Response Number 1
Name: Dr. Nick
Date: November 12, 2005 at 22:57:34 Pacific
Reply:

Maybe.

You still haven't said what you want to do.


0

Response Number 2
Name: G Chen
Date: November 13, 2005 at 05:02:10 Pacific
Reply:

ok. I want to use sed to delete LINE1 and LINE4. I know I can do like:

#Delete LINE1 from input. Save to output1
sed '/LINE1/d' input1 > output1

#Delete LINE4 from output1. Save to output2
sed '/LINE4/d' outputfile1 > outputfil2

In this case I only delete 2 lines but what if I want to delete 100 lines? I don't want to write delete statement and save to a temp output file 100 times. There should be a smarter way or maybe sed is not a good tool to achieve it?

gangchen


0

Response Number 3
Name: Dr. Nick
Date: November 13, 2005 at 11:38:16 Pacific
Reply:

Is there any logic behind the lines you want to delete? Every third line maybe, or is it just 100 arbitrary, random lines?


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: sed remove lines from a file

Script to remove lines from a file www.computing.net/answers/programming/script-to-remove-lines-from-a-file/7090.html

Get first line from a file www.computing.net/answers/programming/get-first-line-from-a-file/14984.html

delete line from the file if there is no thir www.computing.net/answers/programming/delete-line-from-the-file-if-there-is-no-thir/19138.html