如何逃避猛砸/ grep的单引号? [英] How to escape single quotes in Bash/Grep?
本文介绍了如何逃避猛砸/ grep的单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用grep搜索看起来像这样的字符串:
的东西〜*喇嘛
我想这一点,但外壳消除了单引号哎呀..
的grep -i'的东西〜*'[:alnum:]'在/ var / log / syslog的
什么是正确的搜索?
解决方案
的grep -i的东西〜\\ *'[[:alnum:]] */无功/日志/系统日志
我的作品。
- 逃脱首
*
来匹配一个*
,而不是使之成为零或更多的百搭性格:结果〜*
将匹配零个或多个〜
,而结果的〜\\ *
匹配前pression〜*
在的东西
- 使用左右
双括号:alnum:
(参见例如<一个href=\"http://www.gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Ex$p$pssions.html\">here) - 使用
*
在[[:alnum:]]
来搭配,不仅有一个<你的单引号/ STRONG>字符,但其中几个 - 单引号不必在所有的,因为它们都包含在一个前pression由双引号限于被转义。
I want to search with grep for a string that looks like this:
something ~* 'bla'
I tried this, but the shell removes the single quotes argh..
grep -i '"something ~* '[:alnum:]'"' /var/log/syslog
What would be the correct search?
解决方案
grep -i "something ~\* '[[:alnum:]]*'" /var/log/syslog
works for me.
- escape the first
*
to match a literal*
instead of making it the zero-or-more-matches character:
~*
would match zero or more occurrences of~
while
~\*
matches the expression~*
aftersomething
- use double brackets around
:alnum:
(see example here) - use a
*
after[[:alnum::]]
to match not only one character between your single quotes but several of them - the single quotes don't have to be escaped at all because they are contained in an expression that is limited by double quotes.
这篇关于如何逃避猛砸/ grep的单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文