grep 相关

it2022-05-05  138

1) -q 参数,本意是 Quiet; do not write anything to standard output.  Exit immediately with zero status if any match is found, even if an error was detected.   中文意思为,安静模式,不打印任何标准输出。如果有匹配的内容则立即返回状态值0。

经常碰到要判断某个字符串变量是否包含另外一个字符串的问题,使用grep判断,我们其实只想要返回值,不想有任何输出,这时用-q可解决该问题。

a="aa bb cc dd" echo $a | grep "aa"if [ $? -eq 0 ]; then echo "This string is include aa."else  echo "This string is not include aa."fi

 2) -E 支持扩展正则表达式,同egrep

最常见的一个用法是:

egrep “a|b”

表示匹配a或者b

3) -w 单词全匹配,单词间的分隔符包括空格,冒号,逗号等

转载于:https://www.cnblogs.com/ManMonth/p/4329135.html


最新回复(0)