Update a file with other file data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Update a file with other file data
# 1  
Old 05-22-2016
Update a file with other file data

Gents,

Can you help please.

Using information from file1, I will like to update file2.

file1
Code:
X  2922     1581L  30535.00  51881.001    1  3241  30540.00  51666.00  52312.001
X  2922     8931L  30961.00  52625.001    1  4321  30540.00  52194.00  53056.001
X  2922     1711L  30529.00  51881.001    1  3241  30540.00  51666.00  52312.001
X  2922     1691L  30531.00  51881.002    1  3241  30540.00  51666.00  52312.001

file2
Code:
X              1   30529.00  51881.00     1    21  30900.00  52310.00  52312.001
X              1   30529.00  51881.00     3   151  61900.00  52304.00  52316.001
X              1   30531.00  51881.00     1    21  30900.00  52310.00  52312.001
X              1   30531.00  51881.00     3   151  61900.00  52304.00  52316.001
X              1   30533.00  51881.00     1    21  30900.00  52310.00  52312.001
X              1   30533.00  51881.00     3   151  61900.00  52304.00  52316.001
X              1   30961.00  52625.00     1  2251  30900.00  52310.00  52758.001
X              1   30961.00  52625.00   226  2751  41900.00  52732.00  52781.001
X              1   30961.00  52625.00   276  3251  51900.00  52732.00  52781.001
X              1   30961.00  52625.00   326  7571  61900.00  52724.00  53155.001


values in blue are the ones to be extracted from file1 and update in file2
values in red are the key to match in files1 and file2.

Keeping the same format.

Output:

Code:
X  2922     1711L  30529.00  51881.001    1    21  30900.00  52310.00  52312.001
X  2922     1711L  30529.00  51881.001    3   151  61900.00  52304.00  52316.001
X  2922     1691L  30531.00  51881.002    1    21  30900.00  52310.00  52312.001
X  2922     1691L  30531.00  51881.002    3   151  61900.00  52304.00  52316.001
X  2922     1581L  30533.00  51881.001    1    21  30900.00  52310.00  52312.001
X  2922     1581L  30533.00  51881.001    3   151  61900.00  52304.00  52316.001
X  2922     8931L  30961.00  52625.001    1  2251  30900.00  52310.00  52758.001
X  2922     8931L  30961.00  52625.001  226  2751  41900.00  52732.00  52781.001
X  2922     8931L  30961.00  52625.001  276  3251  51900.00  52732.00  52781.001
X  2922     8931L  30961.00  52625.001  326  7571  61900.00  52724.00  53155.001

Thanks for your help.
# 2  
Old 05-22-2016
As noted before:
Quote:
With more than 250 posts we would like to think that you are learning something from all of the help we have provided you in the past. Please try to do this on your own, show us the code you have tried, and tell us what you can't get to work. We'll be happy to help you when you get stuck.

But, we are not here to act as your unpaid programming staff.
# 3  
Old 05-23-2016
Don,
Thanks for your advise... I will try
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

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

3. UNIX for Dummies Questions & Answers

Select last update data based on file name

Hi All, I need to remove all files except the most update data based on date on filename Input data_AIDS_20150312.txt data_AIDS_20150311.txt data_AIDS_20150411.txt data_AIDS_20140312.txt the most updated data is data_AIDS_20150411.txt, so I'll remove other files. My expected output... (3 Replies)
Discussion started by: radius
3 Replies

4. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

5. Shell Programming and Scripting

Script to update data in a file

Hi, I need a script to update a line in a file with a file name everytime it runs. For example below are two files each files contains two rows(say 4&5) which needs to be updated with a file name abc.param xyz.param Now below are two filenames which have date and time appended to... (1 Reply)
Discussion started by: sv0081493
1 Replies

6. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

7. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

8. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

9. Shell Programming and Scripting

Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with. I am trying to format an ldif file so I can import it into Oracle oid. I need the file to look like this example. Keep in mind there are 3000 of these in the file. changetype: modify replace: userpassword dn:... (0 Replies)
Discussion started by: timothyha22
0 Replies
Login or Register to Ask a Question