Comparing 2 files and then apending matches

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 1
Reputation: benjohnson is an unknown quantity at this point 
Solved Threads: 0
benjohnson benjohnson is offline Offline
Newbie Poster

Comparing 2 files and then apending matches

 
0
  #1
Oct 1st, 2007
Hi ,

I have a work project on at the moment and am struggling to find the answer!!

I have 2 files. 1 file contains a huge list of stuff in the following format

123456789 HOSTNAME 0 415 VLR_HPLMN

I then have a file which has an entry in it in the following format

HOSTNAME~123456789~123456789 ANOTHERHOSTNAME 0 415 VLR_HPLMN SIGTRAN




What I need to do , is look down the 2 files, and Match the number from the 1st file, to the number in the 2nd file. If it finds a match I then need to append the differences on the end of the line . i.e in this instance i need to add SIGTRAN on the end of the entry in file 1.

Can anyone help??????
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 54
Reputation: radoulov is an unknown quantity at this point 
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: Comparing 2 files and then apending matches

 
0
  #2
Oct 2nd, 2007
If you want the records that don't match also:

Shell Scripting Syntax (Toggle Plain Text)
  1. awk 'NR==FNR{x[$2]=$NF;next}
  2. $1 in x?$0=$0" "x[$1]:1' FS="[~ ]" file2 file1

Without them:

Shell Scripting Syntax (Toggle Plain Text)
  1. awk 'NR==FNR{x[$2]=$NF;next}
  2. $1 in x?$0=$0" "x[$1]:0' FS="[~ ]" file2 file1

Use nawk or /usr/xpg4/bin/awk on Solaris.
Last edited by radoulov; Oct 2nd, 2007 at 9:24 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC