Dear All,
Can anyone help to remove the , bewteen "" in a string by using sed or awk?
e.g.
input : 1,4,5,"abcdef","we,are,here",4,"help hep"
output:1,4,5,"abcdef","wearehere",4,"help hep"
Thanks,
Mimi
Dear All,
Can anyone help to remove the , bewteen "" in a string by using sed or awk?
e.g.
input : 1,4,5,"abcdef","we,are,here",4,"help hep"
output:1,4,5,"abcdef","wearehere",4,"help hep"
Thanks,
Mimi
Using awk:
awk '{for(i=2;i<=NF;i=i+2)gsub(",","",$i)}1' FS='"' OFS='"' file
Guru
It works!! Thanks
Using sed:
$ cat file
1,4,5,"abcdef","we,are,here",4,"help hep"
$ sed -r ':x s/("[^",]+),([^"]+")/\1\2/; tx' file
1,4,5,"abcdef","wearehere",4,"help hep"
$ sed ':x s_\("[^",]\+\),\([^"]\+"\)_\1\2_; tx' file
1,4,5,"abcdef","wearehere",4,"help hep"
$ echo '1,4,5,"abcdef","we,are,here",4,"help hep"' | sed -e :x -e 's/"\([^",]\{1,\}\),/"\1/g; tx'
1,4,5,"abcdef","wearehere",4,"help hep"
Yes, that's a better solution, a simpler solution. Thanks.
And of course you don't need the two -e expressions, they can be combined into one script.