Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete multiple empty lines with SED?

I'm trying to compress a text document by deleting of duplicated empty lines, with sed. This is what I'm doing (to no avail):

sed -i -E 's/\n{3,}/\n/g' file.txt

I understand that it's not correct, according to this manual, but I can't figure out how to do it correctly. Thanks.

like image 698
yegor256 Avatar asked Dec 18 '25 09:12

yegor256


1 Answers

As tripleee suggested above, I'm using Perl instead of sed:

perl -0777pi -e 's/\n{3,}/\n\n/g'
like image 54
yegor256 Avatar answered Dec 21 '25 12:12

yegor256



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!