删除“空"来自文本文件 shell 脚本的行 [英] remove "empty" lines from a text file shell script

查看:27
本文介绍了删除“空"来自文本文件 shell 脚本的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组输出文件,其中一些如下:

I have a set of output files and some are as below:

133 0.00295 nurse merit respect muslim 
134 0.00292 high dangerous reassure full 
135 0.00048 
136 0.0039  experience darren  
137 0.00097 _ _param_ui_control_scripts_save _param_pattern_value 
138 0.00292 find director

我想得到以下文件:

133 0.00295 nurse merit respect muslim 
134 0.00292 high dangerous reassure full 
136 0.0039  experience darren  
137 0.00097 _ _param_ui_control_scripts_save _param_pattern_value 
138 0.00292 find director

如果在第二列之后没有任何内容,只想删除该特定行.我该怎么做?我对 shell 脚本很陌生?

Just want to remove that particular line if it doesn't have anything after the second column. how can I do this I'm quite new to shell scripting?

可能是对这个命令的修改?sed '/^$/d'

probably a modification of this command? sed '/^$/d'

推荐答案

如果列是空格分隔的,如何检查行是否有两个以上的字段?由于 NF 存储了这个值,你可以简单地说:

If the columns are space separated, what about checking that lines have more than two fields? Since NF stores this value, you can simply say:

awk 'NF>2' file

对于给定的输入,它返回:

For your given input it returns:

133 0.00295 nurse merit respect muslim 
134 0.00292 high dangerous reassure full 
136 0.0039  experience darren  
137 0.00097 _ _param_ui_control_scripts_save _param_pattern_value 
138 0.00292 find director

这篇关于删除“空"来自文本文件 shell 脚本的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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