带有变量的awk [英] Awk with a variable

查看:70
本文介绍了带有变量的awk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个awk命令,以打印出列26中出现"200"的总次数.

I have an awk command to print out the total number of times "200" occurred in column 26.

awk '$26 ~ /200/{n++}; END {print n+0}' testfile

如何修改此语句,以便可以将200作为变量传递?例如如果我有一个变量$ code的值为200

How do I modify this statement so I can pass 200 as a variable? e.g. if I have a variable $code with a value of 200

预先感谢

推荐答案

awk '$26 ~ code {n++} END {print n+0}' code=200 testfile

如果命令行中的文件名格式为var = val,则将其视为变量 任务.将为变量var赋值val.

If a filename on the command line has the form var=val it is treated as a variable assignment. The variable var will be assigned the value val.

§ Awk程序执行

这篇关于带有变量的awk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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