有没有办法做到:
output | grep "string1" | grep "string2"
Run Code Online (Sandbox Code Playgroud)
但是使用awk,没有管道?
就像是:
output | awk '/string1/ | /string2/ {print $XY}'
Run Code Online (Sandbox Code Playgroud)
如果有意义,结果应该是匹配的子集。
Ste*_*ris 11
with的默认操作awk是打印,所以相当于
output | grep string1 | grep string2
Run Code Online (Sandbox Code Playgroud)
是
output | awk '/string1/ && /string2/'
Run Code Online (Sandbox Code Playgroud)
例如
$ cat tst
foo
bar
foobar
barfoo
foothisbarbaz
otherstuff
$ cat tst | awk '/foo/ && /bar/'
foobar
barfoo
foothisbarbaz
Run Code Online (Sandbox Code Playgroud)
如果要awk以任何顺序查找与string1 和 都匹配的行string2,请使用&&:
output | awk '/string1/ && /string2/ {print $XY}'
Run Code Online (Sandbox Code Playgroud)
如果您想匹配其中一个string1或string2(或两者),请使用||:
output | awk '/string1/ || /string2/ {print $XY}'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
292 次 |
| 最近记录: |