AWK删除空白行 [英] AWK remove blank lines

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

问题描述

/./仅删除第一个条件{ print "a"$0 }的空白行,我如何确保脚本删除每个条件的空白行?

The /./ is removing blank lines for the first condition { print "a"$0 } only, how would I ensure the script removes blank lines for every condition ?

awk -F, '/./ { print "a"$0 } NR!=1 { print "b"$0 } { print "c"$0 } END { print "d"$0 }' MyFile

推荐答案

在第一个条件中放入以下条件,并使用if语句进行检查,如下所示:

Put following conditions inside the first one, and check them with if statements, like this:

awk -F, '
    /./ { 
        print "a"$0; 
        if (NR!=1) { print "b"$0 } 
        print "c"$0 
    } 
    END { print "d"$0 }
' MyFile

这篇关于AWK删除空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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