I have an input data file (data.csv) with the below format and I need to update it to get my result
ABC,SOME CONTENT,XYZ,SOME CONTENT,,#AB DEF,,,,,,,,,,,0.1,,
ABC,SOME CONTENT,XY1,SOME CONTENT,,#AB DEF,,,,,,,,,,,0.1,,
ABC,SOME CONTENT,XY2,SOME CONTENT,,#AB DEF,,,,,,,,,,,0.1,,
ABC,SOME CONTENT,XY3,SOME CONTENT,,#AB DEF,,,,,,,,,,,0.1,,
My condition is I have a file (input.txt) with the below content
XYZ
XY3
I need to check the records in data.csv for each value in input.txt and update the value in the column from #AB DEF
to #in some country
and update the value from 0.1
to 0
only for the corresponding records and place it back in the same file.
Result:
ABC,SOME CONTENT,**XYZ**,SOME CONTENT,,**#in some country**,,,,,,,,,,,**0**,,
ABC,SOME CONTENT,**XY1**,SOME CONTENT,,**#AB DEF**,,,,,,,,,,,**0.1**,,
ABC,SOME CONTENT,**XY2**,SOME CONTENT,,**#AB DEF**,,,,,,,,,,,**0.1**,,
ABC,SOME CONTENT,**XY3**,SOME CONTENT,,**#in some country**,,,,,,,,,,,**0**,,
I tried with the below command (I am not sure how to check the condition within the sed command), it updates all the records, I know it is because of g
at the end, but not sure how to limit it only for the records which match my condition of XYZ
sed -i "s|#AB DEF,,,,,,,,,,,0.1,,|#in some country,,,,,,,,,,,0,,|g" data.csv
I have to have #
and spaces
within the data, I tried to put the data into variables and tried to replace it, but sed is identifying there is a special character and failing.