我怎么能折叠此bash命令行成一个awk语句? [英] How can I collapse this bash command line into an awk statement?

查看:102
本文介绍了我怎么能折叠此bash命令行成一个awk语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个awk脚本,并使用它是这样的:

 #的grep -E[PM] [IP] [DO] [:S]file.txt的| AWK-脚本

我怎样才能修改awk脚本,包括grep命令的工作(这是搜索不是PID:或MPOS

AWK-脚本是:

 #!的/ usr /斌/的awk -f
/套/ {
        的printf(%8D,%7D,%7.2f,%7.2f,%7.2f \\ n,$ 5,$ 6,$ 7 $ 30 $ 31)
}
/周围/ {
        的printf(%8D,%7D ,,,,%7.2f,%7.2f \\ n,$ 5,$ 6,$ 7 $ 8)
}
/ MPOS:/ {
        的printf(%8D,%7D ,,,,,,%5D,5D%\\ n,$ 4 $ 5,$ 2,$ 3)
}


解决方案

如果你只是想搜索 PID: MPOS ,你可以说,如果你的在该行不的找到他们,你想跳过以下规则:

 #!的/ usr /斌/的awk -f!/ PID:| MPOS / {
        下一个
}/套/ {
        的printf(%8D,%7D,%7.2f,%7.2f,%7.2f \\ n,$ 5,$ 6,$ 7 $ 30 $ 31)
}
/周围/ {
        的printf(%8D,%7D ,,,,%7.2f,%7.2f \\ n,$ 5,$ 6,$ 7 $ 8)
}
/ MPOS:/ {
        的printf(%8D,%7D ,,,,,,%5D,5D%\\ n,$ 4 $ 5,$ 2,$ 3)
}

I've created an awk script and use it like this:

# grep -E "[PM][IP][DO][:S]" file.txt | awk-script

How can I modify the awk script to include the effort of the grep command (which is searching for either "PID:" or "MPOS"?

awk-script is:

#!/usr/bin/awk -f
/Sleeve/  {
        printf("%8d, %7d, %7.2f, %7.2f, %7.2f\n", $5, $6, $7, $30, $31)
}
/Ambient/ {
        printf("%8d, %7d,,,, %7.2f, %7.2f\n", $5, $6, $7, $8)
}
/MPOS:/ {
        printf("%8d, %7d,,,,,, %5d, %5d\n", $4, $5, $2, $3)
}

解决方案

If you just want to search for PID: or MPOS, you can say that if you don't find them in the line, you want to skip following rules:

#!/usr/bin/awk -f

!/PID:|MPOS/ { 
        next 
}

/Sleeve/  {
        printf("%8d, %7d, %7.2f, %7.2f, %7.2f\n", $5, $6, $7, $30, $31)
}
/Ambient/ {
        printf("%8d, %7d,,,, %7.2f, %7.2f\n", $5, $6, $7, $8)
}
/MPOS:/ {
        printf("%8d, %7d,,,,,, %5d, %5d\n", $4, $5, $2, $3)
}

这篇关于我怎么能折叠此bash命令行成一个awk语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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