簡體   English   中英

如何在grep中轉義單引號

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM