0

Print the lines of file2 that exist in file1

grep -xFf file1 file2

December 11, 2023bashoneliners

Explanation

The meaning of the flags:

  • -x -- match complete lines
  • -F -- treat the patterns as fixed strings instead of regular expressions
  • -f FILE -- take patterns from FILE

All of these flags are critical to perform the intended task accurately.