I want to write a shell command that replaces all newlines from all paragraphs in stdout that match a specific regex with spaces. Here, I'm defining a paragraph to be any text bookended by two or more new lines.
Specifically, I want to locate all paragraphs of text that do not begin with ( or $ and strip these paragraphs of all newlines.
For example, running my script on
Aliquam erat volutpat. Nunc ( eleifend leo vitae magna. In (i)yd erat non orci
commodo lobortis. Proin $ neque massa, cursus ut, gravida ut, lobortis eget,
lacus. Sed diam.
Hello world.
(Nullam tristique diam
non turpis.
Hello
$again!
$foo
bar
should result in
Aliquam erat volutpat. Nunc ( eleifend leo vitae magna. In (i)yd erat non orci commodo lobortis. Proin $ neque massa, cursus ut, gravida ut, lobortis eget, lacus. Sed diam.
Hello world.
(Nullam tristique diam
non turpis.
Hello $again!
$foo
bar
Is this possible?
I don't mind if there's collateral damage like adding extra newlines (but I'm also curious if it can be done without collateral damage!).
perloremacscan handle this easily.