Question

I have a .CSV file with 7 fields, and the 3rd and 4th columns of the file has a number starting with an apostrophe ( ' ). Please see the example below.

col0,col1,col2,col3,col4,col5,col6,
1value0,1value1,'8972991766941,'8972991766941,1value4,1value5,1value6,
2value0,2value1,'8912988876583,'8912988876583,2value4,2value5,2value6,
3value,3value1,'8912981226981,'8912981226981,3value4,3value5,3value6,
2value0,4value1,'8912971783681,'8912971783681,4value4,4value5,4value6,

How do I get rid of the apostrophes in the 3rd and 4th columns only using either sed or awk?

Was it helpful?

Solution

You can use awk:

awk -F, '{for (i=3;i<=4;i++) sub("'\''", "", $i)}1' OFS=, file

OTHER TIPS

If ' is not needed at all, remove it everywhere.

awk '{gsub("'\''","")}1' file

Press CTRL+H on Notepad, replace "'" with "" (Nothing)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top