Issue
I have been looking for a solution for this for days now, I want to replace all spaces only when they occur inside square brackets, and replace them with a double quote, comma, double quote. ---> ","
The solution can be any where as long as it works, but need to say that its a huge file.
An 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"],
Preferable solutions since I am working with these tools: Visual Studio OR Sed.
Thank you
Solution
Using sed
$ sed ':a;s/\(\["[^ ]*\) /\1","/;ta' input_file
"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"],
If the loop does not work for your use case but the pattern will always be the same, you can also try
$ sed 's/\(\[[^ ]*\) /\1","/g' input_file
"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"],
Answered By - HatLess Answer Checked By - Terry (WPSolving Volunteer)