I am trying to remove trailing space after brackets in an HTML file using sed (part of a shell script on CentOS):
from this:
<p>Some text (
<em>Text which should not break to a new line</em>). More text.</p>
to this:
<p>Some text (<em>Text which should not break to a new line</em>). More text.</p>
I can easily do it in Sublime Text with \(\s REGEX and replacing it with a bracket but this does not work in sed.
I have tried:
sed 's/[(]\s*$/(/'
sed 's/[(]\s*$\n/(/'
and many other things, but none of them work.
Any ideas?
Try:
sed ':a;/($/{N;s/\n//;ba}' file
If the line ends with (, appends the next line (N) to the pattern space and then substitutes the newline character \n with nothing, thereby joining the lines. This is done in a loop (ba jumps back to label a).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With