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!

joining of two files

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi all,

i'm trying to join two files. first file looks like:
time longitude latitude height
37786 -8.263067522 -70.642653907 53.916
37816 -8.263069117 -70.642653804 53.738
37846 -8.262415414 -70.642604397 53.503
37876 -8.262414702 -70.642604411 53.529
37906 -8.262414363 -70.642604433 53.589
37936 -8.262414621 -70.642604394 53.562
37966 -8.262414319 -70.642604237 53.555
37996 -8.262414128 -70.642604418 53.615
38026 -8.262414379 -70.642604315 53.558
38056 -8.262415334 -70.642604228 53.465
38086 -8.262415147 -70.642604269 53.484
38116 -8.262414098 -70.642604252 53.566
38146 -8.262414227 -70.642604178 53.546
38176 -8.262413806 -70.642604212 53.595
38206 -8.262414291 -70.642604161 53.553
38236 -8.262413955 -70.642604207 53.570
38266 -8.262414484 -70.642604151 53.527

second looks like:
time latitude logitude height
38115.974 -70.642585923 -8.262413153 49.086
38115.994 -70.642585923 -8.262413152 49.086
38116.014 -70.642585923 -8.262413152 49.086
38116.034 -70.642585923 -8.262413152 49.086
38116.054 -70.642585923 -8.262413153 49.086
38116.074 -70.642585923 -8.262413153 49.086
38116.094 -70.642585923 -8.262413153 49.086
38116.114 -70.642585923 -8.262413153 49.086
38116.134 -70.642585923 -8.262413153 49.086
38116.154 -70.642585922 -8.262413153 49.086
38116.174 -70.642585922 -8.262413153 49.086
38116.194 -70.642585922 -8.262413153 49.086
38116.214 -70.642585922 -8.262413153 49.086
38116.234 -70.642585922 -8.262413153 49.086
38116.254 -70.642585922 -8.262413153 49.086
38116.274 -70.642585922 -8.262413153 49.086
38116.294 -70.642585922 -8.262413154 49.086
38116.314 -70.642585922 -8.262413154 49.086
38116.334 -70.642585922 -8.262413154 49.086
38116.354 -70.642585922 -8.262413154 49.086
38116.374 -70.642585922 -8.262413154 49.086
38116.394 -70.642585922 -8.262413154 49.086
38116.414 -70.642585922 -8.262413154 49.086
38116.434 -70.642585922 -8.262413154 49.086

now, i want to join the files on the time column, so take the time of the first file and find the best fitting time in the second file and then write a file, which looks like:

37786 -8.263067522 -70.642653907 53.916 49.086
37816 -8.263069117 -70.642653804 53.738 49.086
37846 -8.262415414 -70.642604397 53.503 49.086
37876 -8.262414702 -70.642604411 53.529 49.086
37906 -8.262414363 -70.642604433 53.589 49.086
37936 -8.262414621 -70.642604394 53.562 49.086
37966 -8.262414319 -70.642604237 53.555 49.086

that means first three columns of the first file and the forth column of the second file.

can anybody help me?

thanks a lot....tini
 
Hi

Code:
awk 'FNR==NR{s[$1]=$4;next}{d=1000;m=0;for(i in s){e=$1>i?$1-i:i-$1;if(e<d){d=e;m=s[i]}}print $0,m}' second first
Note the order of arguments.
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top