944,117 Members | Top Members by Rank

Ad:
Oct 1st, 2007
0

Comparing 2 files and then apending matches

Expand Post »
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??????
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
benjohnson is offline Offline
1 posts
since Oct 2007
Oct 2nd, 2007
0

Re: Comparing 2 files and then apending matches

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.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
radoulov is offline Offline
54 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Shell Script to CLean up Files
Next Thread in Shell Scripting Forum Timeline: FireWall Back ups with Expect





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC