Update
The problem happens to be with the kind of file you were using. Apparently it came from a DOS system and had many \r
around. To solve it, do "sanitize" them with:
dos2unix
Former answer
Your awk
is pretty fine. However, you can also compare files with grep -f
:
grep -f file1 file2
This will look for lines in file1
that are also in file2
.
You can add options to make a better matching:
grep -wFf file1 file2
-w
matches words-F
matches fixed strings (no regex).
Examples
$ cat a
hello
how are
you
I am fine areare
$ cat b
hel
are
$ grep -f b a
hello
how are
I am fine areare
$ grep -wf b a
how are