2

I am trying to use ack to search (in Haskell files) for +|+

I looked at ack-grep: chars escaping but this doesn't help

On Mac OS X 10.6 I get the following responses:

$ ack -Q +|+
-bash: +: command not found
Missing option after +
ack: See ack --help, ack --help-types or ack --man for options

$ ack \+\|\+
Unknown option: |
ack: See ack --help, ack --help-types or ack --man for options

$ ack [+][|][+]
-bash: ][+]: command not found
ack: Invalid regex '[+][':
  Unmatched [ in regex; marked by <-- HERE in m/[+][ <-- HERE /

$ ack \Q+|+\E
-bash: +E: command not found

That's basically all the suggestions in the Q&A listed above

Community
  • 1
  • 1
  • 1
    The problem here is that you're dealing with two levels of escaping, first `bash` and then `ack` itself. Try putting quotes around the arguments to get them past `bash` then apply the tips in your linked question for `ack`. – hammar Apr 25 '13 at 09:44

2 Answers2

3

This should work as intended:

$ ack "\+\|\+"

(Edited to be correct per your comments. Unquoted pipe is 'or'.)

svk
  • 5,854
  • 17
  • 22
0

The -Q will quote everything in your search string.

ack --haskell -Q '+|+'

which is easier than

ack --haskell "\+\|\+"
Andy Lester
  • 91,102
  • 13
  • 100
  • 152