[英]how to escape single quotes in grep
我在这里发现了一些与此类似的问题,但它们并不完全相同。
我想在某些文件中搜索文本'true' format
。
我该怎么做?
不知道如何转义围绕true
的单引号。
只需将字符串括在双引号内:
grep "'true' format" your_file
$ cat a
this is 'true' format
and this is true formatting
test
$ grep "'true' format" a
this is 'true' format
如果您可以使用grep
的-P
(Perl 正则表达式语法)标志,那么您可以在模式中将'
编码为\\x27
:
grep -P '\x27true\x27 format' file.txt
(同样,对于"
使用\\x22
)
使用转义:
grep -i "'true' format" file.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.