M
M
MIsternik2015-12-29 11:57:37
bash
MIsternik, 2015-12-29 11:57:37

Regular expressions in grep with single quotes and double quotes, what's the difference?

for example, I use a file with the following content:
\x47L
\x47L\x47L
\x47L\x47L\x47L
\x47L\x47L\x47L\x47L
\x47L\x47L\x47L\x47L\x47L
\x47L\x47L\x47L\x47L\x47L\x47L
you need to find lines where '\x47L' is repeated 3 or more times.
grep -E '(\\x[a-zA-Z0-9]{3}){3,}' filename //
grep -E "(\\x[a-zA-Z0-9]{3} works ){3,}" filename //DOES NOT work
grep -E '(\\x47L){3,}' filename //
DOES grep -E "(\\x47L){3,}" filename //DOES NOT work
If in write file :
a
aa
aaa
aaaa
aaaaa
then it works like this:
"(a){3,}"
and like this:
'(a){3,}'
wtf?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
ldv, 2015-12-29
@MIsternik

bash is to blame, in case of double quotes \\ is replaced by \

S
ShamblerR, 2015-02-18
@ShamblerR

will work like this
. But if you use " inside the argument, you may not like it.
So in fact the difference is that they are different characters and if I use the
"date='%Y'" construct, then everything works correctly,
but if
'date='%Y' ' as you understand there will be no kin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question