I want to remove the comma which is present within the double quoted string. All other commas which is present outside double quotes should be present.
Input : a,b,"cc,dd,ee",f,ii,"jj,kk",mmm
output : a,b,"ccddee",f,ii,"jjkk",mmm
I want to remove the comma which is present within the double quoted string. All other commas which is present outside double quotes should be present.
Input : a,b,"cc,dd,ee",f,ii,"jj,kk",mmm
output : a,b,"ccddee",f,ii,"jjkk",mmm
one long-winded way with awk:
echo 'a,b,"cc,dd,ee",f,ii,"jj,kk",mmm' | \
awk -v sep='"' '{
for(i=1;i<=length($0); i++)
{
ch=substr($0,i,1)
if(ch==sep) {inside=!inside}
if (inside && ch==",") {continue}
printf("%s",ch)
}
printf("\n")
}'
Another one:
awk 'BEGIN{FS="\"";OFS=""}{gsub(",","",$2);gsub(",","",$4)}1' file
Regards
OK, no matter how many double quotes you have, you always can use the following awk program:
BEGIN{
FS="\""
OFS="\""
}
{for(i=1;i<=NF;i++)
if(i%2 == 0)
gsub(/,/, "", $i)
print
}