Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a file of email addresses (file 1) and another file (file 2) of lines of data that contain some of these email addresses

I want to compare files and remove all lines in file 2 that have a matching email in file 1.

I know I can do a loop and use sed -i or loop and grep each line to a new file then compare files with COMM

But I was wondering if there is a comparison method that I can kind of grep all lines in file1 to file2 and just be left with the lines from file2 that do not contain any emails in file 1

file 1:

test@invalid.com
test2@invalid.com
test3@invalid.com

file 2:

23456|tom|jones|test@goodemailcom|10
12345|pete|best|pete@goodemail.com|10
87569|remove3|me3|test3@invalid.com|10
23098|mike|jones|mike@goodemailcom|10
10985|al|best|al@goodemail.com|10
09865|removve|me|test@invalid.com|10
13579|remove2|me2|test2@invalid.com|10

Appreciate any knowledge anyone has.

share|improve this question
1  
Ummm ... your example data has all info sitting on one line in both files, items space separated. Is that intentional? –  tink Mar 18 '13 at 19:08

1 Answer 1

You can use fgrep for this:

fgrep -v -f file1  file2  > unique_addresses

This task will be a lot easier if you have 1 email address per line in both files.

Traditionally fgrep exists as a separate program, but in GNU utilities, grep -F does the same thing.

share|improve this answer
1  
For what it's worth, -F is specified by POSIX and in no way limited to GNU. I remember using it on Solaris 10 as well. –  rahmu Mar 18 '13 at 19:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.