Howto use sed to remove only triple empty lines?
For example:
MyText.txt
line1 line2 line3 line4
with the use of sed i want the result to look like this
MyText.txt
line1 line2 line3 line4
I was able to delete double empty lines with
sed -i '/^$/{ N /^\n$/D }' MyText.txt
However my goal is to delete triple empty lines and only triple empty lines.
Any help would be much appreciated.
It's as simple as:
sed '1N;N;/^\n\n$/d;P;D'
It's not sed, but it's a whole lot shorter than what you can do with sed:
$ printf 'a\nb\n\nc\n\n\nd\n' |
perl -e 'undef $/; $_ = <>; s/\n\n\n/\n/g; print'
a
b
c
d
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