Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge two files with comparison 2

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

I have two files.
First file "Chris1.txt"
ckb+:05 17468668 ds09
ckb+:05 1549368 ss09
cup+:03 3654311 ds09
cup+:03 266059 ss09
eel+:04 15392852 ds09
eel+:04 944131 ss09

Second File "Chris2.txt"
ckb+:05 1532093 -827330.22 457510330 26 26 0 ss09
ckb+:05 17390749 38374660.98 1892708517 16395 62 1 ds09
cup+:03 3603298 8126919.54 424256233 3454 78 16 ds09
cup+:03 263078 -142062.12 107577691 0 0 0 ss09
eel+:04 15344006 32111482.32 1874911075 10695 32 1 ds09
eel+:04 933544 -504113.76 398094666 3 3 0 ss09

Desired Output should be
ckb+:05 1549368 1532093 -827330.22 457510330 26 26 0 ss09
ckb+:05 17468668 38374660.98 1892708517 16395 62 1 ds09

I need to compare first $1 and $8 and if true print $1,($2 of Chris1.txt),$2,$3,$4,$5,$6,$7,$8.

Script

awk -v file="Chris1.txt" 'BEGIN{
if(!file)file="Chris1.txt"
while((getline<fn)>0){
a[$1]=$1;b[$1]=$3
}
}
{
if(a[$1])&&(b[$8])
print $1,b[$1],$2,$3,$4,$5,$6,$7,$8
}' Chris2.txt
Many Thanks
Chris
 
nawk -f fran.awk Chris1.txt Chris2.txt

Code:
FNR==NR {
   a[$1,$3]=$2
   next
}
{
   idx=$1 SUBSEP $8
   if ( idx in a) {
      $2 = a[idx] OFS $2
      print
   }
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
thanks

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad,

The best forum and people. A star to you.

Many thanks
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top