如何使用sed仅删除三行空行? [英] Howto use sed to remove only triple empty lines?

查看:53
本文介绍了如何使用sed仅删除三行空行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用sed仅删除三行空行?

Howto use sed to remove only triple empty lines?

例如:

MyText.txt

MyText.txt


line1

line2


line3



line4

使用sed,我希望结果看起来像这样
MyText.txt

with the use of sed i want the result to look like this
MyText.txt


line1

line2


line3
line4

我能够使用


sed -i '/^$/{
N
/^\n$/D
}' MyText.txt

但是我的目标是删除三行空行,而仅删除三行空行.

However my goal is to delete triple empty lines and only triple empty lines.

任何帮助将不胜感激.

推荐答案

它很简单:

sed '1N;N;/^\n\n$/d;P;D'

这篇关于如何使用sed仅删除三行空行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆