Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-06-2010, 12:58 PM   #16
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 548

Rep: Reputation: 116Reputation: 116

If you just want to delete lines in a file containing a particular string, use the following:

sed '/H3qqea3ur6p/d' < oldfile > newfile
I don't know if you want to check for spaces around the word, start and end of lines etc - if you do you will need to modify the above as all that does is look for the existence of the string H3qqea3ur6p and deletes any lines containing it.
Old 01-06-2010, 01:08 PM   #17
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Originally Posted by raj000 View Post

Thanks a ton for your replies. Actually the 2 files are fairly simple text files. Each file contains email addresses in separate row.

File1 -: (this contains about 2000 mails)

File2 -: (this contains about 200 mails that should be deleted from file1)

in the above example, i need a sed command that would take inputs from file2, 1 line at a time, delete and from file1 and output the result to file3.
This may be a better description of what you want to do, if you mean "email addresses" when you say mails and you provided a represented sample of lines from each file.

Since you are using the entire line, you want to be left with a file that contains items in file1 that are unique.

comm -23 <(sort file1) <(sort file2) >file3
The "comm" program prints 3 columns. Files unique to file1, files unique to file 2 and files common to both. The -23 option suppresses the printing of the second and third column.

The "comm" program is one of the programs supplied by the coreutils package so you should have it.
Another way of doing this is using grep with the -f option combined with the -v option. This would remove lines from one file that contains patterns in a second file.

grep -vf <(sort file2 | uniq) file1 >file3
Sorting file2 isn't necessary here but if there is a lot of repetition `uniq' can eliminate the duplicates to save time.

Last edited by jschiwal; 01-06-2010 at 01:21 PM.
Old 01-18-2010, 08:22 AM   #18
LQ Newbie
Registered: Jan 2010
Posts: 2

Rep: Reputation: 0
Originally Posted by cezam View Post
Hi i got the same problem here i want to delete each lines of codes that has H3qqea3ur6p in it which is a virus thats infecting people browsing a site that im hosting.. anyhow the grep -Ev doesn't seem to work for me any suggestions???

i had done 1400 lines of removing code so far lol.. but 700 are still not done.

I cannot see any reason that you cannot delete with grep or sed.
Your pattern H3qqea3ur6p is a simple one.
If you don't need extended regexp or don't know how to use it, you can omit -E switch from grep.

Show us your commands.

Last edited by survietamine; 01-18-2010 at 08:24 AM.
Old 09-08-2012, 09:38 AM   #19
LQ Newbie
Registered: Sep 2012
Posts: 1

Rep: Reputation: Disabled

use grep -v -f [file_delemail] [file_email] > [file_final]


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
Delete text between key words : sed shalomajay Programming 7 05-11-2011 06:22 PM
sed matching an apostrophe dazdaz Linux - General 2 04-28-2006 05:24 PM
pattern matching question - grep cbriscoejr Programming 1 02-09-2006 08:30 PM
Simple Text Reformat (sed and grep) mikefazz Programming 2 08-31-2004 07:38 PM

All times are GMT -5. The time now is 12:17 PM.

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