tags 15937 notabug close 15937 thanks On Wed, Nov 20, 2013 at 11:34 AM, Aaron Selk <[email protected]> wrote: > The following command produces matches. > # egrep ^[\[].+[\]] /var/log/apache2/error.log > > However, if I save the pattern to a file and use the -f option, it produces > no matches. > I have to change the pattern to this: > ^[\[].+\] > > Notice I had to remove the enclosing square brackets to get the literal > closing bracket to match when using the -f option.
Thanks for the report, but the only problem is that you have not quoted the regular expression, and that makes it subject to evaluation by your shell. I suggest trying hard to single-quote (double-quote only when necessary) grep regular expressions that are specified on the command line. This demonstrates that a properly-quoted regexp works the same on the command line as when included as the contents of an -f-specified file: $ echo '[x]' | grep -E '^[[].+[]]' [x] $ echo '[x]' | grep -E -f <(echo '^[[].+[]]') [x]
