grep满足多个|任意关键字或排除多个关键字搜索

grep 同时满足多个关键字和满足任意关键字
① grep -E "word1|word2|word3" file.txt
满足任意条件(word1、word2和word3之一)将匹配。
② grep word1 file.txt | grep word2 |grep word3
必须同时满足三个条件(word1、word2和word3)才匹配。

grep 同时排除多个关键字
例如需要排除 abc.txt 中的 mmm nnn
grep -v 'mmm|nnn' abc.txt

ifconfig | grep inet | grep -v inet6
ifconfig | grep inet | grep -v inet6 | grep -v 127.0.0.1
ifconfig | grep inet | grep -v 'inet6|127.0.0.1' #屏蔽inet6或127xxx

原文地址:https://www.cnblogs.com/bluestorm/p/15426810.html