Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for lines that literally have a greater than character (a ">") followed by a space followed by a backslash character (a "\") i.e., a line with this: > \

I thought escaping would allow this, and for the greater-than it does:

  $ ack-grep "\> "

returns lines that have "> " in them.

But when I try to escape the backslash as well I get:

  $ ack-grep "\> \\"

ack-grep: Invalid regex '\> \':
Trailing \ in regex m/\> \/

share|improve this question

Wow, I was so close ... single quotes:

$ ack-grep '\> \\'

Figured this out after confirming that my regex match was valid using: and just happened to have had single quotes from trying something else.

share|improve this answer

This also works:

$ ack-grep '> \\'

and so does:

$ ack-grep "> \\\\"

The greater-than doesn't need to be escaped.

share|improve this answer

Please note that the issue here is not with ack but with the shell quoting. You'd have this problem with any program that you were trying to pass in "> \" as an argument.

share|improve this answer
Yup, had I known this first: 3.1.11 The golden rules of Bourne shell quoting Everything else that might be maltreated by the shell is protected by single quotes. – Stephen Gornick Jun 1 '10 at 16:00

To search literal strings, use the literal option:

ack-grep --literal '> \'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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