Compare files

Please help me with awk.I have two files with the below details

file1

123456789 2012
987654321 2011
a1234567892012
a1234abcde2012
b1234567892012
c1234567892012
98765a12342012

file2

a1234
01234
b1234
33333

I need to check whether the items in file2 is present in file1 .If it is present , the entire row needs to be removed from file1

File1 is of fixed format.
characters 1-5 item 1
characters 6-10 item 2
characters 11-14 year

Expected output is

123456789 2012
987654321 2011
c1234567892012
98765a12342012

Note that all the duplicates must be removed.e.g. Input file has two

a1234567892012
a1234abcde2012

Both the rows should be removed since it contains a1234

Try this:

awk 'NR==FNR{a[$1];next}!(substr($0,1,5) in a)' file2 file1

Use nawk or /usr/xpg4/bin/awk on Solaris.

1 Like

:b:Thank you!!It worked