awk 'NR==FNR {a[$0]=$0;next}
/^Gr_[0-9]+$/ {key=$0}
($0 in a) { B[a[$0]]=B[a[$0]] "\t" key":"FILENAME}
END { for (i in B){print i FS B}
}' ptr1 file[123]
i tried your code but it gives me syntax error at line 2. :
awk: line 2: syntax error at or near ^
awk: line 2: runaway regular expression /{key=$0}
I understand your not there. as for the above syntax error, i got it when i ran the above sample input files.
Also, for my real input files, it does not mean that all the file name start with "File" and then followed by numbers. It could be any random names. thanks
i am using the one that u gave me as i am testing on the sample input files that i gave.
awk 'NR==FNR {a[$0]=$0;next}
/^Gr_[0-9]+$/ {key=$0}
($0 in a) { B[a[$0]]=B[a[$0]] "\t" key":"FILENAME}
END { for (i in B){print i FS B}
}' ptr1 file[123]
I am not sure, what went wrong. Its working for me. Can you try putting all in single line?
awk 'NR==FNR {a[$0]=$0;next} /^Gr_[0-9]+$/ {key=$0} ($0 in a) { B[a[$0]]=B[a[$0]] "\t" key":"FILENAME} END { for (i in B){print i FS B} }' ptr1 file[123]
Again, Make sure you have ptr1 file and file1,file2,file3 (lower-case)