In Linux, how can I merge two files and only keep lines that have a match in both files?
Each line is separated by a newline (\n
).
So far, I found to sort
it, then use comm -12
. Is this the best approach (assuming it's correct)?
fileA contains
aaa
bbb
ccc
ddd
fileB contains
aaa
ddd
eee
and I'd like a new file to contain
aaa
ddd