Sign up ×
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:

file 2:


Appreciate any knowledge anyone has.

share|improve this question
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
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


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.