Rohan Shah
Rohan Shah

Reputation: 5

Shell script for Converting a record to double quoted comma separated strings

I want to write a shell script for following scenario. I have a record

"apple""banana""pineapple"

And I would like each string to be in double quote, and comma separated, like this:

"apple","banana","pineapple"

Upvotes: 0

Views: 90

Answers (2)

Mustafa DOGRU
Mustafa DOGRU

Reputation: 4112

You can try this

sed 's/""/","/g'

 user@host:~$  echo '"apple""banana""pineapple"' | sed  's/""/","/g'
"apple","banana","pineapple"

Upvotes: 3

Kent
Kent

Reputation: 195039

this awk one-liner should work for the given example:

awk -F'""' -v OFS='","' '$1=$1' 

Upvotes: 1

Related Questions