|
With comments for better understanding
#Opening the file
for i in `cat map | awk 'BEGIN { FS = " " }; { print $1}'`
do
#Column1 in map file is key to file2
mapkey1=$i
mapkey2=`cat map | grep $mapkey1 `
#Column2 in map file is key to file1
mapkey2=`echo $mapkey2 | awk 'BEGIN { FS = " " }; { print $2}'`
#Selecting values from file1 based on mapkey2 from map file
file1key=`cat file1 | grep $mapkey2`
file1key=`echo $file1key | awk 'BEGIN { FS = " " }; { print $2,$3}'`
#Selecting values from file2 based on mapkey1 from map file
file2key=`cat file2 | grep $mapkey1`
file2key=`echo $file2key | awk 'BEGIN { FS = " " }; { print $2,$3}'`
#Diplay the results
echo $i $file1key $file2key
done
|