Artificial intelligent assistant

Replace particular character but not if it is inside () I'm looking for a one-line command to make a file more readable. I want to replace all `;` characters with `newline` unless it is inside a set of `()`. This is on a firewall, so I can only use bash; no perl etc. Example input: ProductName: Threat Emulation; product_family: Threat; Destination: (countryname: United States; IP: 127.0.0.1; repetitions: 1) ; FileName: (file_name: myfile) ; Expected output: ProductName: Threat Emulation product_family: Threat Destination: (countryname: United States; IP: 127.0.0.1; repetitions: 1) FileName: (file_name: myfile)

A little bit confusing regex for sed but workable


sed '
:a #mark return point
s/\(\(^\|)\)[^(]\+\);\s*\([^)]\+\((\|$\)\)/\1\
\3/ #remove ; between ) and (
ta #repeat if substitute success
s/[[:blank:];]\+$// #remove ; with spaces at end
'


Breif regex explanation:

* `^\|)` from the line start or `)`
* `[^(]\+` any symbols but `(`
* `;\s*` semicolon with possible space(s)
* `(\|$` up to the line end or `(`

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 01071449a5cf375d7fc14557d0e9a0e2