我怎么能在bash的一个空行代替复式空行? [英] How can I replace mutliple empty lines with a single empty line in bash?

查看:172
本文介绍了我怎么能在bash的一个空行代替复式空行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文件:

something



something else

something else again

我需要一个bash命令,用sed / grep的w.e,将产生以下输出

I need a bash command, sed/grep w.e that will produce the following output

something

something else

something else again

在换句话说,我需要的只是一个单一的空行来替代多个空行。的grep / sed的是基于行的。我从来没有发现一个bash的解决方案,将在多行正则表达式的模式工作。有什么建议?

In other words, I need to replace multiple blank lines with just a single blank line. grep/sed are line based. I've never found a BASH solution that would work on multi-line regex patterns. Any suggestions?

推荐答案

您只需要 -s 选项:

cat -s

这篇关于我怎么能在bash的一个空行代替复式空行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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