简体   繁体   English

Mac OSX,Bash,awk和负面看后面

[英]Mac OSX, Bash, awk, and negative look behind

I want to find a particular process using awk: 我想使用awk找到一个特定的进程:

ps aux|awk '/plugin-container.*Flash.*/'

Now it finds the process, but it includes itself in the results, because ps results include them as well. 现在它找到了进程,但它将自己包含在结果中,因为ps结果也包含它们。 To prevent that, I am trying to use negative look behind as follows: 为了防止这种情况,我试图使用负面看法如下:

ps aux|awk '/(\?<!awk).*plugin-container.*Flash.*/'

But it does not work. 但它不起作用。 Does awk support look behind? awk支持看后面吗? What am I doing wrong? 我究竟做错了什么? Thanks 谢谢

The common trick is to use 常见的诀窍是使用

ps aux | grep '[p]lugin-container.*Flash.*'

The character class [p] prevents grep itself from being matched. 字符类[p]阻止grep本身匹配。

I don't know whether awk supports lookbehind, but I usually solve this problem with grep -v : 我不知道awk是否支持lookbehind,但我通常用grep -v来解决这个问题:

aix@aix:~$ ps aux | awk '/plugin-container.*Flash/' | grep -v awk

(Also, I'd normally use grep for the awk command above.) (另外,我通常使用grep作为上面的awk命令。)

I don't know if awk supports lookbehinds, but if, then the question mark at the start should not be escaped, a negative lookbehind starts (?<! 我不知道awk是否支持lookbehinds,但是如果,那么开头的问号不应该被转义,负面的lookbehind开始(?<!

A question mark right after the opening bracket is the sign, that this group is not a capturing group, ie it has some special meaning. 开头括号后面的问号是标志,该组不是捕获组,即它具有一些特殊含义。

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

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