使用ksh(AIX)时如何在awk中调用变量?

我正在编写一个脚本,其中需要像这样在awk代码块内传递变量值

$ ps auxw |awk /$variable/ |awk !/awk/ |wc -l

For example. If I were to check the status of cron I would type something as shown below 
$ ps auxw |awk /cron/ |awk !/awk/
root      4980924  0.0  0.0 1276 1300      - A      Jan 07  3:12 /usr/sbin/cron

我使用了ps -ef | grep cron | grep -c -v cron,但是当我执行脚本时,当我只有一行输出时,它将报告两行的行数。 有人可以帮忙吗?

nn0930 回答:使用ksh(AIX)时如何在awk中调用变量?

我想,我已经找到了想要的答案。我只需要在双引号内传递变量。谢谢。

$ svar="cron"
$ ps auxw |awk /"$svar"/ |awk !/awk/
root      4980924  0.0  0.0 1276 1300      - A      Jan 07  3:12 /usr/sbin/cron
本文链接:https://www.f2er.com/2365976.html

大家都在问