I've UTF-8 plain text lists of usernames, 1 per line, in list1.txt
and list2.txt
. Note, in case pertinent, that usernames may contain regex characters e.g. ! ^ . (
and such as well as spaces.
I want to get and save to matches.txt
a list of all unique values occurring in both lists. I've little command line expertise but this almost gets me there:
grep -Ff list1.txt list2.txt > matches.txt
...but that is treating "jdoe"
and "jdoe III"
as a match, returning "jdoe III"
as the matched value. This is incorrect for the task. I need the per-line pattern match to be the whole line, i.e. from ^ to $. I've tried adding the -x flag but that gets no matches at all (edit: see comment to accepted answer - I got the flag order wrong).
I'm on OS X 10.9.5 and I don't have to use grep
- another command line (tool) solving the problem will do.