Avin
Avin

Reputation: 21

Replace Double Quotes comma separator within Brackets [] using sed

I have the data given below with other lines of data in a huge file to be more specific this is a .json file, I have stripped the whole file except for this one catch.

Data:

I want the data to look like this

So far I have this piece of code however it seems to be replacing the whole files "," with , and not the ones just within []

sed 's/\(\[\|\","\|\]\)/\,/g' testfile_1.txt >testfile_2.txt

Any help would be great

**Note: Edited fourth condition

Cheers.

Upvotes: 0

Views: 356

Answers (2)

Avin
Avin

Reputation: 21

Thank you for your contributions @clearlight

Here is my solution to the problem with multiple occurrences;

sed -e ': a' -e 's/\(\[[^]]*\)","/\1,/' -e 't a' testfile_1.txt >testfile_2.txt

Using label 'a' till end of label 'a'

pseudocode:

while (not end of line){ replace "," with ' }

Upvotes: 0

clearlight
clearlight

Reputation: 12615

That's tougher without the non-greedy matching perl regex offers, but this seems to do it.

sed -e 's/\([^\[]*\"[A-Z\-]*\)\",\"\(.*\)/\1,\2/'

Upvotes: 1

Related Questions