Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Find and replace value using a key from other file

$
0
0
Dear Friends,

I am looking for a way how to find and replace a value in two files using a reference a file where are the key to replace.
Basically, I want to keep a copy of the original file and make a new one in order to compare at the end that the change was done whitout change the rest of file..:)

All files are in the same folder.

Then the files are like this

file name = sw1135g.sps
S 2657.00 7305.00 2V1 0.0 0 0.0 420124.9 2571324.9 153.7297152126
S 2657.00 7285.00 2V1 0.0 0 0.0 419125.0 2571325.2 154.6297152202

file name = sw1135g.xps
X 5822 241L 2657.00 7305.002 1 2401 2586.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 241 4801 2596.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 481 7201 2606.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 721 9601 2616.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 961 12001 2626.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 1201 14401 2636.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 1441 16801 2646.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 1681 19201 2656.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 1921 21601 2666.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 2161 24001 2676.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 2401 26401 2686.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 2641 28801 2696.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 2881 31201 2706.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 3121 33601 2716.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 3361 36001 2726.00 7186.00 7425.001
X 5822 241L 2657.00 7305.002 3601 38401 2736.00 7186.00 7425.001
X 5822 251L 2657.00 7285.002 1 2401 2586.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 241 4801 2596.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 481 7201 2606.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 721 9601 2616.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 961 12001 2626.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1201 14401 2636.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1441 16801 2646.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1681 19201 2656.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1921 21601 2666.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2161 24001 2676.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2401 26401 2686.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2641 28801 2696.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2881 31201 2706.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 3121 33601 2716.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 3361 36001 2726.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 3601 38401 2736.00 7166.00 7405.001

filename = datatochange.txt ( reference file )
sw1135g.sps 2657.00 7305.00 2 1
sw1135g.xps 2657.00 7305.00 2 1

Then the desired output

file name = sw1135gnew.sps
S 2657.00 7305.00 1V1 0.0 0 0.0 420124.9 2571324.9 153.7297152126
S 2657.00 7285.00 2V1 0.0 0 0.0 419125.0 2571325.2 154.6297152202

The changed was done in colum 24, value 2 has been replaced by value 1, acoording to file datatochange.txt $5
looking and taking as reference 2657.00 7305.00

file name = sw1135gnew.xps
X 5822 241L 2657.00 7305.001 1 2401 2586.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 241 4801 2596.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 481 7201 2606.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 721 9601 2616.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 961 12001 2626.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 1201 14401 2636.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 1441 16801 2646.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 1681 19201 2656.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 1921 21601 2666.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 2161 24001 2676.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 2401 26401 2686.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 2641 28801 2696.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 2881 31201 2706.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 3121 33601 2716.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 3361 36001 2726.00 7186.00 7425.001
X 5822 241L 2657.00 7305.001 3601 38401 2736.00 7186.00 7425.001
X 5822 251L 2657.00 7285.002 1 2401 2586.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 241 4801 2596.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 481 7201 2606.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 721 9601 2616.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 961 12001 2626.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1201 14401 2636.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1441 16801 2646.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1681 19201 2656.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 1921 21601 2666.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2161 24001 2676.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2401 26401 2686.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2641 28801 2696.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 2881 31201 2706.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 3121 33601 2716.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 3361 36001 2726.00 7166.00 7405.001
X 5822 251L 2657.00 7285.002 3601 38401 2736.00 7166.00 7405.001

The changed was done in colum 38, value 2 has been replaced by value 1, acoording to file datatochange.txt $5
looking and taking as reference 2657.00 7305.00

In the reference file datatochange.txt, I have wrote the name of the file where the changes need to be done. the output name for the new file need to be different. (sw1135gnew.xps example)

I have many files to change it is only a example for one case.

Please let me know if there is other way to do it,

Any help on this will be strongly appreciated.

Thanks in advance :)

Viewing all articles
Browse latest Browse all 16232

Trending Articles