Replace values using other file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace values using other file
# 1  
Old 10-16-2015
Replace values using other file

Gents,

Please can you help me.

I need to update file1 using file2 values

file1
Code:
S  44519.00  49349.00  1V1     0.0   0     0.0      0.0       0.0   0.0289091513
S  44513.00  48581.00  1V1     0.0   0     0.0      0.0       0.0   0.0289094319
S  44511.00  48605.00  1V1     0.0   0     0.0      0.0       0.0   0.0289103039
S  44519.00  48449.00  1V1     0.0   0     0.0      0.0       0.0   0.0289110005
S  44515.00  49265.00  1V1     0.0   0     0.0      0.0       0.0   0.0289112202

file2
Code:
S  44023.00  47789.00  14      0.0   0         451962.8 2491789.1 128.9289111908
S  44519.00  49349.00  14      0.0   0         468912.0 2491962.3 108.9289111921
S  44115.00  47741.00  14      0.0   0         451362.8 2492937.8 127.4289111926
S  44513.00  48481.00  14      0.0   0         468762.5 2491812.3 108.8289111942
S  44035.00  49421.00  24      0.0   0         472361.5 2491936.5 111.6289111956
S  44511.00  48605.00  14      0.0   0         451962.6 2491761.8 129.2289112000
S  44519.00  48449.00  14      0.0   0         470412.8 2497187.3 110.4289112002
S  44113.00  47741.00  14      0.0   0         451364.4 2492913.4 127.9289112019
S  44515.00  49265.00  14      0.0   0         468911.8 2491987.3 110.6289112020

output
Code:
S  44519.00  49349.00  1V1     0.0   0     0.0 468912.0 2491962.3 108.9289111921
S  44513.00  48581.00  1V1     0.0   0     0.0 468762.5 2491812.3 108.8289111942
S  44511.00  48605.00  1V1     0.0   0     0.0 451962.6 2491761.8 129.2289112000
S  44519.00  48449.00  1V1     0.0   0     0.0 470412.8 2497187.3 110.4289112002
S  44515.00  49265.00  1V1     0.0   0     0.0 468911.8 2491987.3 110.6289112020


Thanks for your helpSmilie

Last edited by jiam912; 10-16-2015 at 03:23 PM..
# 2  
Old 10-16-2015
Hi, try:
Code:
awk 'NR==FNR{A[$2,$3]=$7 OFS $8 OFS $9; next} ($2,$3) in A{sub(/ *[^ ]* *[^ ]* *[^ ]* *$/, OFS A[$2,$3])}1' file2 file1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace values on file

Gents, Please i need your help. Using the file2.txt i will like to replace values in file3.txt. Example in file 2 column 1 is the value to find in file3.txt and replace with value in colunm2 (file2.txt). Example file2.txt 21 1209 22 1210file3.txt SCI TB Timestamp Local : 8/30/17... (2 Replies)
Discussion started by: jiam912
2 Replies

2. Shell Programming and Scripting

Read a file and replace values in a script

Hi , I have a property file placed in folder /usr/opt/temp/aorc.prop which has values given below . I need to read this file content and replace the node with actual values in a shell script . Each time the script shall replace the node value from the poperty file and execute a cfsend command and... (10 Replies)
Discussion started by: samrat dutta
10 Replies

3. Shell Programming and Scripting

Replace column values from other file

I have one file as it has the following format File1 S No Site IP Address 1 Australia 192.168.0.1/26 2 Australia 192.168.0.2/26 3 Australia 192.168.0.3/26 I need awk/sed command to replace the column2 value ( under Site) with some other... (8 Replies)
Discussion started by: samaritan
8 Replies

4. Shell Programming and Scripting

Replace two values in a file with input from two different files

Hi, I was having the following issue cat input hello1, my name is unix.com. I am awesome. Hope you know this, hello2! cat hello1.txt Hi Friends Hi Folks Hi Well-Wishers cat hello2.txt Honey Sweety Darling Required Output (8 Replies)
Discussion started by: jacobs.smith
8 Replies

5. Shell Programming and Scripting

Replace a field where values are null in a file.

Hi, I've a pipe delimited file and wanted to replace the 3rd field to 099990 where the values are null. How can I achieve it using awk or sed. 20130516|00000061|02210|111554|03710|2|205069|SM APPL $80-100 RTL|S 20130516|00000061|02210|111554|03710|2|205069|SM APPL $80-100 RTL|S... (12 Replies)
Discussion started by: rudoraj
12 Replies

6. Shell Programming and Scripting

use some part of variable value to replace ../../ values in a file

hi, i have variable value as follows val="/dir1/dir2/dir3/dir4/dir5/dir6/file1" it is pointing to some file location. and i have another file as ../../dir4/file3 ../../dir4/dir5/file4 ../../dir7/file5 i want the output as /dir1/dir2/dir3/dir4/file3 (7 Replies)
Discussion started by: snreddy_gopu
7 Replies

7. UNIX for Dummies Questions & Answers

replace a column with values from another file

Dear all, I have a file1.pdb in pdb format and a dat file2 containing values, corresponding to the atoms in the pdb file. these values (file2.dat) need to be in the column instead of the 0.00 (file1) values for each atom in file1.pdb .(the red values must be replaced by the blue ones,in order)... (11 Replies)
Discussion started by: chen.xiao.po
11 Replies

8. UNIX for Dummies Questions & Answers

Replace values in a specified column of a file

Hello, I have a file with four columns and I would like to replace values in the second column only. An arbitrary example is: 100 A 105 B 200 B 205 C 300 C 305 D 400 D 405 E 500 E 505 F I need to replace the second column as shown below: ... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

9. UNIX for Dummies Questions & Answers

Find and Replace based on values in an file

I have a file in which I want to do multiple find and replace of strings. For a single replace I can implement: sed -i 's/old/new/' <input_file> I have a second file that contains the old and the new values like the arbitrary example below: old new xyz pqr ab 756 rst pqr... (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

10. HP-UX

Replace all 'low values" in a file

Hi, I've to replace all low values (hex '00') in a flat file (containing more than 1,000,000 records) with space (hex '20'). I try to use: awk '{gsub("\x00","\x20")}' file_name and I obtain the following response: awk: Line AP000010536900577986 cannot have more than 199 fields.... (2 Replies)
Discussion started by: sw.an
2 Replies
Login or Register to Ask a Question