Reputation: 462
I have the following situation:
source.txt
ID1:[email protected]
ID2:[email protected]
ID3:[email protected]
...
IDs are numeric strings, e.g. 1234
, 23412
, 897
... (one or more digits).
exclude.txt
[email protected]
[email protected]
[email protected]
...
i.e. only emails, no IDs.
I want to remove all lines from source.txt which contain emails listed in exclude.txt, preserving the ID:email
pairs for the lines which are not removed.
How can I do that with linux command line tools (or simple bash script if needed)?
Upvotes: 2
Views: 51
Reputation: 6335
You can do it easily with awk:
awk -F":" 'NR==FNR{a[$1];next}(!($2 in a))' exclude.txt source.txt
Alternative with grep:
grep -v -F -f exclude.txt source.txt
Use grep with care, since grep does a regex matching. You might need to add also -w option to grep (word matching)
Upvotes: 2