how to remove the double quotes in a csv
Simplest approach:
tr -d '"' <a.csv >b.csv
Use gsub()
function for global substitution
$ awk '{gsub(/\"/,"")};1' input.csv
1,2,3,4,9
1,2,3,6,24
1,2,6,8,28
1,2,4,6,30
To send output to new file use >
shell operator:
awk '{gsub(/\"/,"")};1' input.csv > output.csv
Your splitting to array approach also can be used, although it's not necessary, but you can use it as so:
$ awk '{split($0,a,"\""); print a[2]}' input.cvs
1,2,3,4,9
1,2,3,6,24
1,2,6,8,28
1,2,4,6,30
Note that in this particular question the general pattern is that quotes are in the beginning and end of the line, which means we can also treat that as field separator, where field 1 is null, field 2 is 1,2,3,4
, and field 3 is also null. Thus, we can do:
awk -F '\"' '{print $2}' input.csv
And we can also take out substring of the whole line:
awk '{print substr($0,2,length($0)-2)}' quoted.csv
Speaking of stripping first and last characters, there's a whole post on stackoverflow about that with other tools such as sed
and POSIX shell.
Another solution with sed
:
sed -e 's/"//g' a.csv > b.csv