Update file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Update file
# 1  
Old 12-01-2015
Update file

Gents

Please can you help.

file1
Code:
   43067.00  49301.00                                                  314999999
   43067.00  49157.00                                                  313888888
   43065.00  49157.00                                                  313777777
   43063.00  49157.00                                                  313666666

file2
Code:
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
Code:
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
Code:
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
# 2  
Old 12-01-2015
Try
Code:
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

This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-01-2015
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
Code:
   43067.00  49301.00                                                     999999
   43067.00  49157.00                                                     888888
   43065.00  49157.00                                                     777777
   43063.00  49157.00                                                     666666

file2
Code:
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
Code:
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..
# 4  
Old 12-02-2015
Hello jiam912,

Could you please try following and let me know if this helps you.
Code:
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.
Code:
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
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 12-02-2015
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.
These 2 Users Gave Thanks to RudiC For This Post:
# 6  
Old 12-02-2015
RudiC,

Thanks a lot for the explanation.. and the update of the code.

R. Singh

Thanks for your code.. works fine also
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Move file from one directory and update the list file once moved.

Dears, I have a listfile contains list of files path. i need to read the line of the listfile mv the file to other directory and update the listfile by deleting the lines of the listfile. #!/bin/bash target=/fstest/INVESTIG/Sadiq/TEST_ARCH while read -r line || ]; do mv $line... (19 Replies)
Discussion started by: sadique.manzar
19 Replies

3. Shell Programming and Scripting

awk to update file with sum of matching fields in another file

In the awk below I am trying to add a penalty to a score to each matching $1 in file2 based on the sum of $3+$4 (variable TL) from file1. Then the $4 value in file1 is divided by TL and multiplied by 100 (this valvue is variable S). Finally, $2 in file2 - S gives the updated $2 result in file2.... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Perl to update field in file based of match to another file

In the perl below I am trying to set/update the value of $14 (last field) in file2, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (4 Replies)
Discussion started by: cmccabe
4 Replies

5. Programming

MYSQL - trigger update on record insert or update

Right I have a MYSQL database with table1 with 3 columns, colA, colB and colC. I want to combine the data in the 3 columns into a 4th column names col_comb. Here's the SQL command that works: UPDATE table1 SET `col_comb` = CONCAT( `colA` , ' - ', `colB` , ', ', `colC` ); So now I want this... (5 Replies)
Discussion started by: barrydocks
5 Replies

6. Shell Programming and Scripting

rsync - update file on backup when file renamed on source

hi all, Please help me with rsync. I configured rsync to preserve timestamps using the -a option. When i renamed fileA to fileB on source machine I have to copies at the backup server. The aim is to keep the most recent file. fileA & fileB has same contents. When i renamed fileB to... (2 Replies)
Discussion started by: coolatt
2 Replies

7. Shell Programming and Scripting

how to update a file

-Hi, I have several hundred files, which contain the following pattern: /bb/bin/msga/mm 80& I need to change the above pattern to be /bb/bin/mm 80& I there the command I can use to do that. Thanks a lot (3 Replies)
Discussion started by: aoussenko
3 Replies

8. Shell Programming and Scripting

update a file with values from other file in shell bash

Hello I need to write a shell script to update properties between files. I have 2 files as follow: file1 urlWebserviceCheckAddress^=McoConfigGlobal.commonGLOBALUrlWebservice file 2 urlWebserviceCheckAddress=http://localhost:8080/tags Both files containt the same properties... (1 Reply)
Discussion started by: teodora
1 Replies

9. Shell Programming and Scripting

file update

how to update file in unix ? (8 Replies)
Discussion started by: piyush_movadiya
8 Replies
Login or Register to Ask a Question