-w switch returns matches that form whole words.
The reason that it returns
ABHD14A-ACY1 and not
RPL41 is because
ACY1 is at the end of the first and second lines whereas
RPL4 is neither at the beginning nor end of any lines nor is it followed by a non-word constituent character which means anything other than a letter, number, or underscore. This is covered in the
man page for
To test this, if you add a
1 the end of the first line so that it's
1 ABHD14A-ACY11 and remove the 1 from the end of the sixth line so that it's
6 RPL4 then your output will look like this:
There isn't a way to not return the first line with the exact command that you have or with just calling
grep on it's own. You'd have to pipe it into
sed to remove the first line:
grep -Fwf list1.txt list2.txt | sed '/ABHD14A/d'
Or pipe it into
awk to only print what
grep returns after the line containing what you don't want to match:
grep -Fwf list1.txt list2.txt | awk 'NR>1'
Or pipe it into grep -v to exclude the first line:
grep -Fwf list1.txt list2.txt | grep -v ^1
There are other ways to do it but those are the easiest and allow you to just pipe what you have already have.