In-place replacement

awk, sed

Solution

You should choose one of the two tools. As for `sed`, it can be done as follows:

sed -ri 's/^(([^,]*,){34})0([^,]*)/\1+91\3/' test.csv 

Not sure about `awk`, but @shellter's comment might help with that.

Problem

I have a CSV. I want to edit the 35th field of the CSV and write the change back to the 35th field. This is what I am doing on bash: ``` awk -F "," '{print $35}' test.csv | sed -i 's/^0/+91/g' ``` so, I am pulling the 35th entry using awk and then replacing the "0" in the starting position in the string with "+91". This one works perfet and I get desired output on the console. Now I want this new entry to get written in the file. I am thinking of sed's "in -place" replacement feature but this fetuare needs and input file. In above command, I cannot provide input file because my primary command is awk and sed is taking the input from awk. Thanks.

Original source