Sponsored Content
Top Forums Shell Programming and Scripting Update a file with other file data Post 302973828 by jiam912 on Sunday 22nd of May 2016 05:50:12 PM
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.
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
XZDIFF(1)							     XZ Utils								 XZDIFF(1)

NAME
xzcmp, xzdiff, lzcmp, lzdiff - compare compressed files SYNOPSIS
xzcmp [cmp_options] file1 [file2] xzdiff [diff_options] file1 [file2] lzcmp [cmp_options] file1 [file2] lzdiff [diff_options] file1 [file2] DESCRIPTION
xzcmp and xdiff invoke cmp(1) or diff(1) on files compressed with xz(1), lzma(1), gzip(1), or bzip2(1). All options specified are passed directly to cmp or diff. If only one file is specified, then the files compared are file1 (which must have a suffix of a supported com- pression format) and file1 from which the compression format suffix has been stripped. If two files are specified, then they are uncom- pressed if necessary and fed to cmp(1) or diff(1). The exit status from cmp or diff is preserved. The names lzcmp and lzdiff are provided for backward compatibility with LZMA Utils. SEE ALSO
cmp(1), diff(1), xz(1), gzip(1), bzip2(1), zdiff(1) BUGS
Messages from the cmp(1) or diff(1) programs refer to temporary filenames instead of those specified. Tukaani 2009-07-05 XZDIFF(1)
All times are GMT -4. The time now is 06:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy