Compare 2 files and extract the data which is present in other file - awk is not working

file2 content

f1

file2 content

f1,1,2,3,4,5
f1,2,4,6,8,10
f10,1,2,3,4,5
f10,2,4,6,8,10
f5,1,2,3,4,5
f5,2,4,6,8,10
awk 'FNR==NR{a[$1];next}; !($1 in a)' file2 file1

output

f10,1,2,3,4,5
f10,2,4,6,8,10
f5,1,2,3,4,5
f5,2,4,6,8,10
awk 'FNR==NR{a[$1];next}; ($1 in a)' file2 file1

output

nothing displaying

any help, I am using ksh, thanks!

I think you want awk to recognize comma-separated fields, so set the field delimiter to a comma

awk -F, ...

And, reverse the order of the input files...

Thank you for quick support, it is working fine after giving:

awk -F, 'FNR==NR{a[$1];next}; ($1 in a)' f1 f2

output

f1,1,2,3,4,5
f1,2,4,6,8,10

Note that in post #1 in this thread you show us the contents of two files named file2 and you use, but do not show us the contents of a file named file1 .

In post #4 you use files named f1 and f2 , but have never shown us what is in either of those files.

I would expect that you got the results you wanted from the code you showed us in post #4 if the first file you showed us in post #1 was named f1 and the second file you showed us was named f2 . Is that what you intended?