search for the contents in many file and print that file using shell script

hello
have a file1
H87I
Y788O
T347U
J23U

and
file2 J23U U887Y I99U T556U
file3 I99O J99T F557J
file4 N99I T666U R55Y
file5 H87I T347U
file6 H77U R556Y E44T
file7 Y788O K98U H8I

May be using script we can use file1 to search for all the files
and have the output
H87I file5
Y788O file7
T347U file5
J23U file2
Thanks

Do this..you should get what you want..

while read line
do
filefound=`grep -l $line file2 file3 file4 file5 file6 file7`
output=`echo $filefound | cut -d: -f1`
echo "$line $output"
done < file1

cheers,
Devaraj Takhellambam

Thanks pretty works with 20 different files ...ha.........

Hi,
I think this one is ok.

input:

a:
H87I
Y788O
T347U
J23U

b:
file2 J23U U887Y I99U T556U
file3 I99O J99T F557J
file4 N99I T666U R55Y
file5 H87I T347U
file6 H77U R556Y E44T
file7 Y788O K98U H8I

code:

awk '
{
if (NF==1)
	a[$1]=$1
else
	for (i in a)
		if($2==a)
			a=$1
}
END{
for (i in a)
print i " "a
}' a b

output:

H87I file5
J23U file2
T347U T347U
Y788O file7