SiliconBadger
SiliconBadger

Reputation: 177

Escaping metacharacters using grep on cygwin

Using grep on cygwin to search for 'employee_id' with the following conditions:

The expression that follows works in Regex Builder 2.05 using a sample of text, but does not return results when used in grep as such:

grep -E -r '[^_]employee_id[ \]\.]' ./*

I'm not sure if this is some peculiarity of entering expressions via command line, or if it has to do with differences between the many regex "dialects", but I haven't come across any alternative way of escaping characters in my search for an answer.

Can someone provide the correct grep syntax to return the results I'm looking for?

Upvotes: 1

Views: 192

Answers (1)

anubhava
anubhava

Reputation: 785128

You can use:

grep -E -r '(^|[^_])employee_id[] .]' .
  • (^|[^_]) as employee_id can be at line start or be preceded by any non underscore character.

  • There is no need to escape DOT or ] inside character class. But keep in mind that closing ] must immediately follow opening [

Upvotes: 1

Related Questions