繁体   English   中英

awk使用{print $ x}在输出中增加一行

[英]awk print an extra line in output with {print $x}

我没有成功地搜索答案...在RHEL Linux上,第一个命令列出了这一点(对于那些想要测试的人,我正好给出了我得到的东西...):

ps -eaf | grep lsnr | grep -v ' LISTENER ' | grep -v grep
oracle   10258     1  0  2014 ?        01:34:43 /logicielPR1/oracle/product/11.2.0.4/bin/tnslsnr PRXPLO -inherit
oracle   10442     1  0  2014 ?        00:24:30 /logicielTE1/oracle/product/11.2.0.4/bin/tnslsnr TECHIMIO -inherit
oracle   10473     1  0  2014 ?        00:28:50 /logicielTE1/oracle/product/11.2.0.4/bin/tnslsnr TEIAC -inherit
oracle   10566     1  0  2014 ?        00:24:50 /logicielTE1/oracle/product/11.2.0.4/bin/tnslsnr TEIMG -inherit
oracle   14192     1  0  2014 ?        00:22:09 /logicielPR1/oracle/product/11.2.0.4/bin/tnslsnr PROCTM2 -inherit
oracle   27167     1  0  2014 ?        00:19:26 /logicielTE1/oracle/product/11.2.0.4/bin/tnslsnr TEOCTM -inherit
oracle   36854     1  0  2014 ?        00:19:59 /logicielTE1/oracle/product/11.2.0.4/bin/tnslsnr TEANA -inherit
oracle   37235     1  0 May20 ?        00:08:32 /logicielPR1/oracle/product/11.2.0.4/bin/tnslsnr PRCHIMIO -inherit
oracle   45141     1  0 Jun03 ?        00:08:02 /logicielST1/oracle/product/11.2.0.4/bin/tnslsnr PRIACS -inherit
oracle   48241     1  0 Sep25 ?        00:04:39 /logicielPR1/oracle/product/11.2.0.4/bin/tnslsnr PRINL -inherit
oracle   48708     1  0 Sep25 ?        00:03:27 /logicielTE1/oracle/product/11.2.0.4/bin/tnslsnr TEINL2 -inherit

我想提取大写名称(例如第一行上的PRXPLO),所以我这样做:

ps -eaf | grep lsnr | grep -v ' LISTENER ' | grep -v grep | awk -F "${ORA_LISTENER_HEADER}|${ORA_LISTENER_HEADER_UPPER}|tnslsnr " '{print $2}'
PRXPLO -inherit
TECHIMIO -inherit
TEIAC -inherit
TEIMG -inherit
PROCTM2 -inherit
TEOCTM -inherit
TEANA -inherit
PRCHIMIO -inherit
PRIACS -inherit
 {print $2}
PRINL -inherit
TEINL2 -inherit

*注意:在此命令中,“ $ {ORA_LISTENER_HEADER} | $ {ORA_LISTENER_HEADER_UPPER} | tnslsnr”将等同于“ tnslsnr”

显然,包含“ {print $ 2}”的行不应该存在,但是我找不到它的来源。 我知道我可以简单地通过grep排除它,但是我更希望了解我做错了什么。

有人可以帮我解决这个问题吗?

谢谢大家

为了缓解问题,只需使用一个awk调用:

ps -eaf | awk '/lsnr/ && !/ LISTENER / {print $(NF-1)}'

是的,您必须通过grep排除它。 awk是一个独立的进程,它通过运行整个链显示在grep的进程列表中。

ps -eaf | grep lsnr | grep -v ' LISTENER ' | grep -v grep | grep -v awk | awk -F "${ORA_LISTENER_HEADER}|${ORA_LISTENER_HEADER_UPPER}|tnslsnr " '{print $2}'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM