简体   繁体   中英

how to escape single quotes in grep

I found a few questions here similar to this but they are not quite identical.

I want to grep for the text 'true' format in certain files.

How do I do it?

Not sure how to escape the single quotes around true .

Just wrap the string within double quotes:

grep "'true' format" your_file

Test

$ cat a
this is 'true' format
and this is true formatting
test

$ grep "'true' format" a
this is 'true' format

If you can use the -P (Perl regex syntax) flag of grep , then you can encode ' as \\x27 in the pattern:

grep -P '\x27true\x27 format' file.txt

(Similarly, for " use \\x22 )

使用转义:

grep -i "'true' format" file.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM