The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 10-07-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,086
awk

Hi,
I think this one is ok.

input:
Code:
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:
Code:
awk '
{
if (NF==1)
	a[$1]=$1
else
	for (i in a)
		if($2==a[i])
			a[i]=$1
}
END{
for (i in a)
print i " "a[i]
}' a b
output:
Code:
H87I file5
J23U file2
T347U T347U
Y788O file7