I want to search with grep for a string that looks like this:
something ~* 'bla'
I tried this, but the shell removes the single quotes argh..
grep -i '"something ~* '[:alnum:]'"' /var/log/syslog
What would be the correct search?
I want to search with grep for a string that looks like this:
something ~* 'bla'
I tried this, but the shell removes the single quotes argh..
grep -i '"something ~* '[:alnum:]'"' /var/log/syslog
What would be the correct search?
[[:alnum:]]
(two brackets)[[:alnum:]]
is matching only one character. To match zero or more characters[[:alnum:]]*
you can just use
" "
to quote the regex:Matteo
If you do need to look for quotes in quotes in quotes, there are ugly constructs that will do it.
works as expected, but for another level of nesting, the following doesn't work as expected:
Instead, you need to escape the inner single quotes outside the single-quoted string:
Or, if you prefer:
It ain't pretty, but it works. :)
Of course, all this is moot if you put things in variables.
:-)
works for me.
*
to match a literal*
instead of making it the zero-or-more-matches character:~*
would match zero or more occurrences of~
while~\*
matches the expression~*
aftersomething
:alnum:
(see example here)*
after[[:alnum::]]
to match not only one character between your single quotes but several of themIt seems as per your expression, that you are using first
'
, then"
. If you want to escape the single quotes, you can either use'
and escape them, or use double quotes. Also, as Matteo comments, character classes have double square brackets Either:or