无法使用sed正则表达式删除空行 [英] Can't remove empty lines with sed regex

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

问题描述

我有一个像这样的文件:

I have a file like this:

2733617     3.00    3   3

2733617 E1b1    8.00    8   16
2733617 E1b1b1b 2.00    2   4

2733617 I1  294.00  296 590
2733617 I2  1.00    1   2

2733617 I2a1    2.00    2   4

sed '/^$/d'对我不起作用. Outfile看起来就像infile.它应该删除空行.

sed '/^$/d' does not work for me. Outfile looks just like infile. It should remove empty lines.

推荐答案

不幸的是,该手册说使用[!-~]之类的范围并不安全.但是,仅使用:print:打印包含可打印字符的行最终对我有用:

Unfortunately the manual says that using ranges like [!-~] is not safe. However, just printing the lines that containing printable characters using :print: worked for me in the end:

sed -n '/[[:print:]]/p'

这篇关于无法使用sed正则表达式删除空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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