When I run this:

find . -name "my.log*.gz" -print | \
parallel zgrep -e "\(text1\|text2\).*Exception"

to find all lines that match /(text1|text2).*Exception/ in all files in the folder, I get this error message:

zsh:1: no matches found: (text1|text2).*Exception

From the error message, I think (text1|text2).*Exception is being treated as a file name. What am I doing wrong here?

  • Just to be sure: what parallel command are you running? The command from the 'moreutils' package, or the 'GNU parallel' command from the 'parallel' package? – ozzy Jan 15 '19 at 20:41
  • Note that grep expects one or more filenames as arguments on the commandline, or file contents on stdin. In contrast, your command feeds filenames on stdin (via the pipe), which will not work. In addition, if you are using the parallel command from the moreutils package, the syntax is off. – ozzy Jan 15 '19 at 21:03

Use -E for extended regex

find . -name "my.log*.gz" -print | \
parallel zgrep -E "\(text1\|text2\).*Exception"
| improve this answer | |

You need more quoting:

find . -name "*.gz" -print |
  parallel -q zgrep -e "\(text1\|text2\).*Exception"

Use -vv and --dr to see what is really being run.

| improve this answer | |

If you are using the parallel command from the moreutils package, your command could be simplified like this:

parallel zgrep -e "\(text1\|text2\).*Exception" -- my.log*.gz

This will run parallel instances of zgrep, one for each file matching the shell pattern my.log*.gz. Note that the pattern is expanded by the shell before the command is executed. Hence there is no need for a separate invocation of find.

| improve this answer | |

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.