In a very long line I'll summarize with:
(foo),(bar,baz(word,right),(end)
I want to print only:
(bar,baz(word,right
To match the second parenthesis, I exclude the word that follows the third one:
$ grep -oP "\\(.*(?!word).*right"
but Bash interprets the exclamation mark:
-bash: !word: event not found
Protecting the exclamation mark with single quote fails with grep: missing )
$ grep -oP '\\(.*(?!word).*right'
$ grep -oP '\\((?!word)(.*right)'
Protecting the exclamation mark with backslash fails with grep: unrecognized character after (? or (?-
Any idea?
Note: -P
is for Perl regex and -o
is to print only the matching part of a line
grep -o '(b[^)]*'
works in that case. Your attempted usage of the negative look ahead operator doesn't make sense. What exactly do you want to match? – Stéphane Chazelas Mar 31 '14 at 14:03set +H
to turn off history expansion,set -H
to turn it back on. – glenn jackman Mar 31 '14 at 14:15