Click here to Skip to main content
15,943,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am trying to replace spaces in brackes with ","

for example:

"NIST 800-171A": ["3.11.2[a] 3.11.2 3.11.2[c] 3.11.2[d] 3.11.2[e] 3.11.3[a] 3.11.3"],
Will be:
"NIST 800-171A": ["3.11.2[a]","3.11.2","3.11.2[c]","3.11.2[d]","3.11.2[e]","3.11.3[a]","3.11.3"],

There are other spaces in the lines before and after the closed brackets, but I do not want other spaces in the line to be effected. and if the brackets do not contain spaces then nothing changes

Another approach, is to replace all spaces after a column, space , opening bracket which I think would be easier as follows:
: [

Thank you for your help in advance :)

What I have tried:

I tried many regex's using sed command, but my knowledge with sed is minimal.

A solution using Visual code studio would also work if possible.
Updated 29-Jan-23 19:34pm

1 solution

Since you mentioned sed:

In bash shell
$> echo ["2.11.2[a] 3.22.3[b] 4.33.4[c]"] | sed -E 's/ /\",\"/g'

If that works you might be able to redirect from a file line by line.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900