Single Field to multiple fields searching

I have a fileA with one column (1000 rows), and fileB with 26 columns(13000 rows).
I need to search each value of fileA with fileB and return all the 26 values from FileB to a new file- File C if matches. The search value (from FileA) may present in any of the 26 values in FileB. This value is not fixed in any of the columns in B file.

FILEA:

abc
def
ghi
FILEB:

drm|fdm|pln|ess|abc|zeh|....|yer (26 values)
fdm|drm|def|ess|yer|zeh|....|pln

Here, abc from fileA is 5th col. of FileB-so my result should be all the 26 values from FileB to a new file- File C.
Similarly, def from fileA is 3rd col. of FileB -so my result should be all the 26 values from FileB to a new file- File C.

This way, need to do for the entire record set.

If unmatched, ignore the record.

How about:

grep -wf FILEA FILEB

Thanks for the reply!

This code is not working in this scenario. I need to search and return the values to the new file. Tried with the below code also, not worked. Please help if awk command or any other works.

grep -Fwf FileA FileB

I don't understand what is not working are you getting any sort of error message?

If it's just not creating FileC with the results then just redirect the output like this:

grep -wf FileA FileB > FileC

There is no error message, the new file is getting created. But it's an empty file!

grep -wf <server path fileA> <server path fileB> > <server path for new file with 777 permission>

awk 'NR == FNR {A[$0]; next}
 {for(x in A) {if($0 ~ "(^||)" x "(||$)") {print; next}}}' FILEA FILEB > FILEC

I'm surprised this didn't work for you.

It looks like your grep supports -w as you didn't get any errors about unknown parameters. What OS are you doing this on?

Perhaps the files are in DOS format, in which case SriniShoo's solution will probably result in no output either. You could try dos2unix FileA and dos2unix FileB and running the grep again.

1 Like

After conversion from Dos2unix, i got the output generated... :slight_smile: thanks a lot for the quick response.