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 -->
  #5 (permalink)  
Old 07-03-2009
prasperl prasperl is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 22
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