如何在grep中隐藏括号 [英] How to escape parenthesis in grep
本文介绍了如何在grep中隐藏括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在目录中的所有JavaScript文件中grep一个函数调用'init()'。我如何使用grep来做到这一点?
特别是,如何避免括号()
?
解决方案
这取决于。如果你使用普通的grep,你不会转义:
echo'(foo)'| grep'(fo *)'
如果您想将括号用作分组,您实际上必须转义。
如果您使用扩展正则表达式,您的确可以逃脱:
$ p $ echo'(foo)'| grep -E'\(fo * \)'
I want to grep for a function call 'init()' in all JavaScript files in a directory. How do I do this using grep?
Particularly, how do I escape parenthesis, ()
?
解决方案
It depends. If you use regular grep, you don't escape:
echo '(foo)'|grep '(fo*)'
You actually have to escape if you want to use the parentheses as grouping.
If you use extended regular expressions, you do escape:
echo '(foo)'|grep -E '\(fo*\)'
这篇关于如何在grep中隐藏括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文