I am trying to parse the following line using sed to replace a whitespace with a newline only when the whitespace doesn't precede a colon.
For example, I'm using the following input to be processed:
label1: output label2: output2 label3: "output3" label4: output4 { label5: output5 label6: output6 } label7: output7 { { { label8: output8 } label9: output9 } } label10: output10
I'd like regex to replace any whitespace that doesn't have a colon before it with a newline, so the output would be something like this:
label1: output
label2: output2
label3: "output3"
label4: output4
{
label5: output5
label6: output6
}
label7: output7
{
{
{
label8: output8
label9: output9
}
}
label10: output10
When I try using the following regex in cat file | sed 's/[^:A-Za-z0-9\"] /%/g' | tr '%' '\n'
, it results in the output below, which is close but not achieving the goal:
label1: output label2: output2 label3: "output3" label4: output4
label5: output5 label6: output6
label7: output7
label8: output8
label9: output9
label10: output10
I've also tried this cat file | sed 's/[^:A-Za-z0-9\"] /%/g' | tr '%' '\n'
, and it results in
label1: outpu
label2: output
label3: "output3
label4: output
label5: output
label6: output
label7: output
label8: output
label9: output
label10: output10
Which looks like the regex also includes replacing every other character that's not a :
with a newline.