Replace a value using a reference data from other file
Gents,
Can you please help me to solve this case
In my input file I have a values in column 49 which always need to be one, but sometimes the system create a value 2, in this case I need to go to search in the original file and replace the values in the row where the value 2 is and in the previous.
Example input file
The situation is when the value in column 49 changes to value = 2, then I need to change some values in row where it is value 2 and previous row.
changes need to be done in previous row , column 46 , 72
next row , column 41, 49, 52
using the values in original file.
Values in original file
Desire output file
Files attached , hope can help me.
The output.txt file doesn't match your description (code written to match expected output)
ie:
changes need to be done in previous row , column 48 , 76
next row , column 43, 49, 55and 56
using the values in original file. next row also need a "x" appended
Dear XL
Thanks a lot for your script works fine.
But please can you change it to let it works even if the original_file.txt and the input file have different location when it finds the value =2 in column 49
Input file
Example
Code:
X 4708 3010 69523.00 19321.001 1 1461 69524.00 19254.00 19544.001
X 4708 3010 69523.00 19321.001 147 2761 69536.00 19286.00 19544.001
X 4708 3010 69523.00 19321.001 277 3921 69548.00 19314.00 19544.001
X 4708 3010 69523.00 19321.001 393 4921 69560.00 19346.00 19544.001
X 4708 3010 69523.00 19321.001 493 5571 69572.00 19416.00 19544.001
X 4708 3010 69523.00 19321.001 558 6101 69584.00 19440.00 19544.001
X 4708 3010 69523.00 19321.001 611 6531 69596.00 19460.00 19544.001
X 4708 3010 69523.00 19321.001 654 6861 69608.00 19480.00 19544.001
X 4708 3010 69523.00 19321.001 687 7111 69620.00 19496.00 19544.001
X 4708 3010 69523.00 19321.001 712 7281 69632.00 19512.00 19544.001
X 4708 3010 69523.00 19321.001 729 7391 69644.00 19524.00 19544.001
X 4708 3110 69523.00 19353.001 1 1621 69524.00 19254.00 19576.001
X 4708 3110 69523.00 19353.001 163 3081 69536.00 19286.00 19576.001
X 4708 3110 69523.00 19353.001 309 4401 69548.00 19314.00 19576.001
X 4708 3110 69523.00 19353.001 441 5561 69560.00 19346.00 19576.001
X 4708 3110 69523.00 19353.001 557 6371 69572.00 19416.00 19576.001
X 4708 3110 69523.00 19353.001 638 7061 69584.00 19440.00 19576.001
X 4708 3110 69523.00 19353.001 707 7651 69596.00 19460.00 19576.001
X 4708 3110 69523.00 19353.001 766 8141 69608.00 19480.00 19576.001
X 4708 3110 69523.00 19353.001 815 8551 69620.00 19496.00 19576.001
X 4708 3110 69523.00 19353.001 856 8881 69632.00 19512.00 19576.001
X 4708 3110 69523.00 19353.001 889 9151 69644.00 19524.00 19576.001
X 4708 3110 69523.00 19353.001 916 9311 69656.00 19546.00 19576.001
X 4708 3110 69523.00 19353.001 932 9331 69668.00 19572.00 19574.001
X 4708 3110 69523.00 19353.001 934 9352 69668.00 19576.00 19576.001
original_file.txt
Code:
X 69523.00 19353.001 1 1621 69524.00 19254.00 19576.001
X 69523.00 19353.001 163 3081 69536.00 19286.00 19576.001
X 69523.00 19353.001 309 4401 69548.00 19314.00 19576.001
X 69523.00 19353.001 441 5561 69560.00 19346.00 19576.001
X 69523.00 19353.001 557 6371 69572.00 19416.00 19576.001
X 69523.00 19353.001 638 7061 69584.00 19440.00 19576.001
X 69523.00 19353.001 707 7651 69596.00 19460.00 19576.001
X 69523.00 19353.001 766 8141 69608.00 19480.00 19576.001
X 69523.00 19353.001 815 8551 69620.00 19496.00 19576.001
X 69523.00 19353.001 856 8881 69632.00 19512.00 19576.001
X 69523.00 19353.001 889 9151 69644.00 19524.00 19576.001
X 69523.00 19353.001 916 9311 69656.00 19546.00 19576.001
X 69523.00 19353.001 932 9341 69668.00 19572.00 19576.001
X 69523.00 19353.001 935 9351 69680.00 19576.00 19576.001
The key is to find the match the key substr($0,20,18).
Hope you can help me. I have tested it and works fine but needs to have the values to compare exactly in the same row in both files but sometimes I have more data can be in original or input files and the script give other information.
Dear XL
You are perfect.
Thanks a lot for your support.
It works fine but only in two changes.
I have attached the original files I have and you can see that the output is different to the original one.
Sorry to write again,, looks like there is small thing to change.
Example the output should take the values in original file row 23975 and change in row 13151 in input file.. But it write somethings else in output?. I don't know from where it take the values.
Attached input original and output file after run the script (.zip ) fle
Hi,
I'd be grateful for your help with the following:
I have a file with a single column (file1). Let's say the values are:
a
b
c
5
d
I have a second, reference file (ref_file), which is colon-delimited, and is effectively a key. Let's say the values in it are:
a:1
b:2
c:3
d:4... (4 Replies)
Gents,
Please can you help with this.
I have a big file (file2) which contends many records increment every 25 rows ( column 1 ).
Then I have other file as reference (file1).. column 1 to 11.
I want to compare that all values in file2 (column 2 to 12.) match with values in... (2 Replies)
Basically want to replace any field in input file from the refernce file ...
for example.
clar_2400:3113 in input file will be replaced by clar_2400:3113
Input file field seperator is ","
Field which is not found in reference will stay as it is ...
Input File
... (3 Replies)
Dear All,
I am struggling with the following task and would appreciate some help. I have a large table (file1.txt). The first column of this table contains an ID. I would like to replace the ID with a label according to a reference file.
Here is an example:
cat infile.txt
0 AJ2312 310 ... (7 Replies)
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)
Hi All,
I have two files one of which having some mobile numbers and corresponding value whose sample content as follows:
9058629605,8.0
9122828964,30.0
And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,):
... (8 Replies)
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)