Q:

Using a Perl script to compare two files

I am trying to write a Perl/AWK script to compare two files' output in this format shown below:
(As of now I can diff the two files using
grep -Fxvf file1 file2 > file3 which is not sufficient.)
Note: file1 is a superset of file2.
file1:
aaaa
bbbb
cccc
dddd

file2:
bbbb
cccc

Expected output file:
aaaa  No
bbbb  yes
cccc  yes
dddd  No

A:

With awk:
awk 'NR == FNR { a[$0]; next } { print $0, ($0 in a ? "yes" : "no") }' file2 file1

That is:
NR == FNR {                             # while processing the first file
  a[$0]                                 # (i.e., file2) just remember what you
  next                                  # saw, and don't do anything else
}
{                                       # afterwards:
  print $0, ($0 in a ? "yes" : "no")    # print the line followed by "yes" or
                                        # "no" depending on whether the line
                                        # was seen before in file2
}

