Linux - delete multiple lines using one command

el123 used Ask the Experts™
Hi guys,

I'm sure this must be an easy question for you "Gurus".

I've a file, having hundreds of email addresses, and every time, I've to delete some lines or email address from this file, because of its newer version nature, every time, its updated with some new email address, but these addresses have to be removed.

How I can do this, using one command or some facility.

What I'm doing right now: open this file using vi
and then one by one delete lines using:
:%g/junk/d - global delete

but need to do this for each argument, and now their number is also increasing, so I want some kind of help, which makes my life easy, instead of deleting executing this cmd one by one, just in one command, will be able to delete all those arguments only.

Thanks in advance.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007
You can do

sed -i '/junk/d' file

or if you want to combine more than one string

sed -i -e '/junk/d' -e '/string/d' file

I am not sure that I understand the exact nature of the problem.  Are the email addresses different - as in updated with new email addresses - or is this a problem where records are being duplicated.
If it is the later then the uniq utility may be helpful but it will on remove duplicates that are adjacent so it requires a sort first.  If these records have multiple lines for entry then the operation is more difficult.

If this doesn't help please provide more information about how the records stored in the document - it's layout - and what fields are duplicated and where they appear in the document.
sort -u duplicates.txt | uniq -u > no-duplicates.txt

Open in new window



will update soon ...
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.


thanks both of you ... but just last query

it works, I've to put all of my arguments:

sed -i -e '/one/d' -e '/two/d' -e '/three/d' -e '/four/d'-e '/five/d' -e '/six/d' file

and it worked fine, but is there any way, that I'll put all these arguments in one file, and then just execute some script, put this same command in script file, this'll help to add & delete arguments, and this will be fast too, as no need to type again and again, just create the file and run the script, and all these arguments will eb removed from the master file ... please suggest, and thanks again for your help.



guys, please assist, I was able to remove the files, but have to include all the ones ...

sed -i - e '/1st/' -e '/2nd/' -e /'3rd/' ... so on

is it possible that create a file, which will read from a file, where I just need to write or add all those arguments, that needs to be removed ...

please assist, thanks.
Top Expert 2007
Just create a file, eg: file.sed with



then just call it like

sed -i -f file.sed file

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial