Gents
Please can you help.
file1
43067.00 49301.00 314999999
43067.00 49157.00 313888888
43065.00 49157.00 313777777
43063.00 49157.00 313666666
file2
S 43067.00 49301.00 1V1 0.0 0 0.0 470862.5 2479837.5 0.0313224330
S 43067.00 49157.00 1V1 0.0 0 0.0 469062.5 2479837.5 0.0314010456
S 43065.00 49157.00 1V1 0.0 0 0.0 469062.5 2479812.5 0.0314010541
S 43063.00 49157.00 1V1 0.0 0 0.0 469062.5 2479787.5 0.0314010627
output desired
S 43067.00 49301.00 1V1 0.0 0 0.0 470862.5 2479837.5 0.0314999999
S 43067.00 49157.00 1V1 0.0 0 0.0 469062.5 2479837.5 0.0313888888
S 43065.00 49157.00 1V1 0.0 0 0.0 469062.5 2479812.5 0.0313777777
S 43063.00 49157.00 1V1 0.0 0 0.0 469062.5 2479787.5 0.0313666666
I am trying
awk 'NR==FNR{A[$1,$2]=substr($0,72,9) ; next} ($1,$2) in A{sub(/ *[^ ]* *[^ ]* *[^ ]* *$/, OFS A[$1,$2])}1' tmp1 tmp2
But I can not get it... please can you help
Thanks
RudiC
December 1, 2015, 2:54pm
2
Try
awk '
NR==FNR {A[$1,$2]=$NF/1E10
next
}
($2,$3) in A {sub ($NF "$", A[$2,$3])
}
1
' CONVFMT="%12.10f" file1 file2
S 43067.00 49301.00 1V1 0.0 0 0.0 470862.5 2479837.5 0.0314999999
S 43067.00 49157.00 1V1 0.0 0 0.0 469062.5 2479837.5 0.0313888888
S 43065.00 49157.00 1V1 0.0 0 0.0 469062.5 2479812.5 0.0313777777
S 43063.00 49157.00 1V1 0.0 0 0.0 469062.5 2479787.5 0.0313666666
1 Like
RudiC,
Yes it works perfect.. Thanks a lot
---------- Post updated at 05:15 PM ---------- Previous update was at 03:36 PM ----------
Dear RudiC
Please how I can update the code for this case
file1
43067.00 49301.00 999999
43067.00 49157.00 888888
43065.00 49157.00 777777
43063.00 49157.00 666666
file2
S 43067.00 49301.00 1V1 0.0 0 0.0 470862.5 2479837.5 0.0313224330
S 43067.00 49157.00 1V1 0.0 0 0.0 469062.5 2479837.5 0.0314010456
S 43065.00 49157.00 1V1 0.0 0 0.0 469062.5 2479812.5 0.0314010541
S 43063.00 49157.00 1V1 0.0 0 0.0 469062.5 2479787.5 0.0314010627
output desired
S 43067.00 49301.00 1V1 0.0 0 0.0 470862.5 2479837.5 0.0313999999
S 43067.00 49157.00 1V1 0.0 0 0.0 469062.5 2479837.5 0.0314888888
S 43065.00 49157.00 1V1 0.0 0 0.0 469062.5 2479812.5 0.0314777777
S 43063.00 49157.00 1V1 0.0 0 0.0 469062.5 2479787.5 0.0314666666
I am trying to understand this part of code =$NF/1E10
.. but i can not .. can you explain please..
Hello jiam912,
Could you please try following and let me know if this helps you.
awk 'FNR==NR{A[$1 OFS $2]=$NF;next} ($2 OFS $3 in A){sub($NF, substr($NF,1,5) A[$2 OFS $3]);print}' Input_file1 Input_file2
Output will be as follows.
S 43067.00 49301.00 1V1 0.0 0 0.0 470862.5 2479837.5 0.031999999
S 43067.00 49157.00 1V1 0.0 0 0.0 469062.5 2479837.5 0.031888888
S 43065.00 49157.00 1V1 0.0 0 0.0 469062.5 2479812.5 0.031777777
S 43063.00 49157.00 1V1 0.0 0 0.0 469062.5 2479787.5 0.031666666
Thanks,
R. Singh
1 Like
RudiC
December 2, 2015, 4:44am
5
1E10
is the "computational" representation of the engineering/scientific notation 1.0 * 10^10
, so in that example, NF is divided by 10000000000. To adapt to your new requirement, try assigning $NF/1E6
to A[$1,$2]
, and then use (int($NF*1000) + A[$2,$3]) / 1000
in the second part.
2 Likes
RudiC,
Thanks a lot for the explanation.. and the update of the code.
R. Singh
Thanks for your code.. works fine also