views:

50

answers:

4

Hi all, I've done some searching for this but cannot find what I'm after, specifically.

I have two files: "a.txt", "b.txt".

Each contains a list of email addresses, separated by newlines.

For all lines in "a.txt", I need to check for a match anywhere in "b.txt". If so, the email address in "a.txt" needs to be removed.

(Alternatively, a new file "c.txt" could be created with the output if that is easier.)

I'm using Mac OS X, so am looking for a shell script that could help, or pointers to how I'd go about constructing the script. Thanks for any help.

+3  A: 
grep -F -x -f b.txt -v a.txt > c.txt

or, equivalently,

fgrep -x -f b.txt -v a.txt
Alex Martelli
Thank you VERY much to everyone who helped with this. I used this particular tip, but appreciate everyone's help greatly.
SirRatty
+2  A: 

Use comm command like this:

cat a.txt | sort > a2.txt
cat b.txt | sort > b2.txt
comm -23 a2.txt b2.txt > c.txt
DVK
A: 
awk 'FNR==NR{_[$1];next}(!($1 in _))' b.txt a.txt > c.txt
ghostdog74
A: 

I like the grep/fgrep answer, but here is another cat/sort option:

cat a.txt b.txt | sort -u > c.txt
DevNull
that's not what OP is looking for.
ghostdog74
oops. You're right; I read the post completely wrong. Sorry SirRatty!
DevNull