1

Problem

I tried to implement a negative lookahead when searching a file with locate like this:

locate --regex "apple(?!t)"

However I'm getting the following error, because there seems to be some substitution going on:

locate: invalid regexp `apple(?touch latex_preamble.tex)': Invalid preceding regular expression

How can I make this work? I tried apple(?!t) and apple(?!t) as well.

NOTE: I'm aware I can do this with:

locate apple | grep -v applet

but I would like to know how I can get the regular expression to work.

1

There are several implementations of locate, and the ones I'm aware of want either POSIX extended regexps, or POSIX basic regexps. Neither support lookaheads.

1
  • Thank you! In that case I'll have to resort to grep.
    – Daniel
    Jul 17 '15 at 16:23

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.