Edit csv file

I'm trying to replace the content of cell 4A a csv file with another value. The code itself is successful, but when I try to save the newly changed file content into the old file, it doesn't work:

awk -F"," 'NR==4{$1="\"newcontent\","$3}1' test.csv | sed 's/ //g' > test.csv

It works only if I save it to another file:

awk -F"," 'NR==4{$1="\"newcontent\","$3}1' test.csv | sed 's/ //g' > test2.csv

Do I really have to save the changed file content into another file? Maybe I can save it to a temporary file that is removed automatically, and then save that content into the test.csv?

You can also replace the spaces with the awk command:

awk -F, 'NR==4{$1="\"newcontent\","$3}{gsub(" ",x)}1' test.csv > temp
mv temp test.csv
1 Like