Hi Gurus,
I need a script to compare two files: sample file like below:
list:
cde,file4
cde,file5
def,file6
def,file7
def,file8
abc,file1
abc,file2
abc,file3
acd,file9
acd,file10
tmp
file1
file2
file3
file4
file5
file6
I want to compare tmp file file name with list file 2nd column, if file name in both file, then print entire record from list, if file name only exists in list then print "not found" plus the record. for above two file, I except get below result:
cde,file4
cde,file5
def,file6
Not Found def,file7
Not Found def,file8
abc,file1
abc,file2
abc,file3
Not Found acd,file9
Not Found acd,file10
I tried below script, but the output is wrong.
awk -F"," 'NR==FNR{a[$1];next}{if (a[$2])print a[$1],$0;else print "Not Found", $0;}' tmp list
the output as below:
Not Found cde,file4
Not Found cde,file5
Not Found def,file6
Not Found def,file7
Not Found def,file8
Not Found abc,file1
Not Found abc,file2
Not Found abc,file3
Not Found acd,file9
Not Found acd,file10
Hope the experts in the forum take a look, tell me where I did wrong and how to fix this.
Thanks in advance