I have strings per line like:

" … “es” completed."
" … “en” completed."
" … “fr” completed."

I am trying to grep inverse match of all this. That is avoid output all the lines that match with the pattern.

echo " … “es” completed." | grep -v " … “(*)” completed."
echo " … “es” completed." | grep -v " … “[*]” completed."
echo " … “en” completed." | grep -v " … “[\w]” completed."
echo " … “fr” completed." | grep -v " … “[\W]” completed."

All this grep ways still output the strings, I don't know if I need use -e as option parameter, but I am not getting the desired result

  • You need to use a regular expression that matches the strings, for example, " … “..” completed\." - not a "wildcard" – steeldriver Sep 13 '17 at 23:40

-e PATTERN, --regexp=PATTERN Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). (-e is specified by POSIX .)

Yes, you should use -e. But also regex up, especially with double quotes in double quotes, dots and asteriks.

Lets say I do not want any line that ends with completed.

| grep -v -e '.*completed\.$'

  • $ end of string or line
  • * zero or more occurences
  • . matches almost everything
  • \ escape characters, in this case .
|improve this answer|||||
  • I gonna try, the problem is that there is more "completed" strings, so I really need the full regex. Also notice that the double quotes are not normal like ", are “ (probably difficult to notice) – shakaran Sep 14 '17 at 0:24
  • 1
    It seems that grep -v -e " … “.*” completed\.$" work perfect ;) – shakaran Sep 14 '17 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.