-2

This is my input:

"a","b","c","d",",","f"

Expected output:

"a","b","c","d","","f"

Basically for every occurring ",", I want to replace it with "". Also I want to run the command for n number of lines of for n number of fields.

I have tried the below command

awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' infile

But it removes double quotes too but that is not what I require... I require double quotes also

  • 3
    Stack Overflow is no "Post your question and get code"-site... Please show us what you've tried so far. – Seth Jul 25 '16 at 12:49
  • 3
    [What have you tried so far?](http://whathaveyoutried.com) Please [edit] your question to show a [mcve] of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Jul 25 '16 at 12:50
  • @Seth I have tried below command but it reomves double quotes and I dnt want to remove it.. awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' infile – Rohan Shah Jul 25 '16 at 14:34
  • Possible duplicate of [Should I use AWK or SED to remove commas between quotation marks from a CSV file? (BASH)](http://stackoverflow.com/questions/33620713/should-i-use-awk-or-sed-to-remove-commas-between-quotation-marks-from-a-csv-file) – tripleee Jul 25 '16 at 14:47

2 Answers2

1

You can try this

echo '"a","b","c","d",",","f"'  | sed 's/,",",/,"",/g'
Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24
0

Perhaps this works:

echo '"a","b","c","d",",","f"' | awk '{sub(/\42,\42,\42/,"\42,\42\42")}1'
"a","b","c","d","","f"
Claes Wikner
  • 1,457
  • 1
  • 9
  • 8