欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

grep awk 同时排除多个关键字 有大用 有大大用 有大大大用

[root@localhost ~]# cat aa.txt

abc111

abc def

adcdef

zzzz

5555

[root@localhost ~]# awk '/abc/ && !/def/' aa.txt

abc111

image.png



If you want to do this in one pass, you can use awk instead of grep.

Format:

echo "some text" | awk '/pattern to match/ && !/pattern to exclude/'

Examples:

  • echo "hello there" | awk '/hello/ && !/there/'

Returns nothing.

  • echo "hello thre" | awk '/hello/ && !/there/'

Returns: hello thre

  • echo "hllo there" | awk '/hello/ && !/there/'


普通分类: