otherwise BCSpeciality would get matched for example..
The order does not matter if you use:
awk 'NR==FNR{A[$0];next}$0 in A' file1 file2
S.
--
kurumi, I get:
-e:1: undefined local variable or method `a' for main:Object (NameError)
---------- Post updated at 07:16 ---------- Previous update was at 06:57 ----------
rdcwayx,
by using $1 instead of $0 awk would match words instead of lines. It could well be that is what the OP actually intended - in fact that would seem likely - so your awk would be better suited and then
For this task, the order is irrelevant; a successful match must only occur when the line is in both files.
The problem here is the use of regular expressions for what is a fixed-string job. The -f option without -F uses basic regular expressions. If they aren't wrapped with "^" and "$", they allow substring matches to occur. That's incorrect for this case. Matches must be whole lines.
To make matters worse, if a line contains a regular expression special character (such as a "."), it may match a character that is not its literal self. Properly escaping a file to protect against this is error prone.
The correct solution is to avoid regular expressions and instead use fixed strings (-F) that must match an entire line (-x).