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??????

If you want the records that don't match also:

awk 'NR==FNR{x[$2]=$NF;next}
$1 in x?$0=$0" "x[$1]:1' FS="[~ ]" file2 file1

Without them:

awk 'NR==FNR{x[$2]=$NF;next}
$1 in x?$0=$0" "x[$1]:0' FS="[~ ]" file2 file1

Use nawk or /usr/xpg4/bin/awk on Solaris.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.