Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to escape single quotes in grep

Tags:

linux

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.

like image 337
peter.petrov Avatar asked May 21 '14 15:05

peter.petrov


2 Answers

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
like image 126
fedorqui 'SO stop harming' Avatar answered Oct 18 '22 21:10

fedorqui 'SO stop harming'


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)

like image 30
alexandroid Avatar answered Oct 18 '22 21:10

alexandroid