Check whether all lines of file occur in different file

comm -13 <(sort -u file_1) <(sort -u file_2)

This command will output lines unique to file_2. So, if output is empty, then all file_2 lines are contained in the file_1.

From comm's man:

   With  no  options,  produce  three-column  output.  Column one contains
   lines unique to FILE1, column two contains lines unique to  FILE2,  and
   column three contains lines common to both files.

   -1     suppress column 1 (lines unique to FILE1)

   -2     suppress column 2 (lines unique to FILE2)

   -3     suppress column 3 (lines that appear in both files)

[ $(grep -cxFf file2 <(sort -u file1)) = $(sort -u file2 | wc -l) ] && 
  echo all there || 
  echo some missing

If the number of matches from file2 in (the unique lines of) file1 is the same as the number of unique lines in file2, then they're all there; otherwise, they aren't.


Using GNU awk where it does support specific length(array) feature (and some other awk implementation which may can support) and not required if files are sorted.

gawk 'FNR==NR{seen[$0];next} ($0 in seen){delete seen[$0]};
    END{print (!length(seen))?"Matched":"Not Matched"}' file2 file1

This is reading file2 into an array called seen with the key as entire line of file2.

Then read file1 and for each line if matched with lines in array seen then delete that key.

At the end if the array was empty means all lines in file2 exist in file1 and will print Matched, otherwise will display Not Matched.


For the compatibility in all awk implementations.

awk 'FNR==NR{seen[$0];next} ($0 in seen){delete seen[$0]};
    END{for(x in seen);print (!x)?"Matched":"Not Matched"}' file2 file1

To ignoring empty lines/or lines with whitespaces only if in file2, you would need to add NF to the condition in NR==FNR && NF {... to skip reading them into the array.