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 -->
  #1 (permalink)  
Old 07-17-2008
sickboy sickboy is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 62
Matching and combining two files

Hi there,

I have two files. What I want to do is search for the values in second field of file1 in the 6th field of the file2 and of they match to add the fields 1-5 of the file2 at the end of the line of file1 with a comma before.

E.g
Code:
File1
FWB,CHUAGT87HUMAS/BUD01,REUAIR08KLM
FWB,CHUAGT87HUMAS/BUD01,REUAIR08MPH
FHL,CHUAGT87HUMAS/BUD03,REUAIR08KLM
FHL,CHUAGT87HUMAS/BUD03,REUAIR08AFR
FSR,CHUAGT87HUMAS/BUD03,REUAIR08KLM
Code:
File2
HU,ARTUKJK HLDHLL,Budapest,0,NIL,CHUAGT87HUMAS/BUD01
ZA,HHHJKJH,Cape Town,7747046,2005,REUAGT82BURL/CPT01
ZA,JHKKB BKJB,Cape Town,7747046,8003,REUAGT87BAX/CPT01
GB,HMBKLJBHJO,Cardiff,9147007,204,REUAGT87BAX/CWL01
GB,UJHJKHJK,Cardiff,9147069,205,REUAGT82SHNK/CWL01
US,UIGHIKUHKJHJ,Charlotte,110608,452,REUAGT87BAX/CLT01
So the entry in the new file will look
Code:
Newfile
FWB,CHUAGT87HUMAS/BUD01,REUAIR08KLM,HU,ARTUKJK HLDHLL,Budapest,0,NIL
Thanks in advance!