Jaqueline fernadas
Jaqueline fernadas

Reputation: 33

What is the use of grep -e "Pattern" --regexp=Pattern?

I know when we are using a

grep -e "hello" -e "helo" 

this will match both hello and helo, but I saw the following in the man page:

-e PATTERN, --regexp=PATTERN

What is the meaning of regexp?

Upvotes: 1

Views: 96

Answers (2)

fedorqui
fedorqui

Reputation: 290075

This means that you can use either -e or --regexp with the same parameters to get the same behaviour.

So the following are equivalent:

grep -e "hello" -e "helo"
grep --regexp='helo' --regexp='hello'

Note you can get the same behaviour with the regular grep by escaping |:

grep "hello\|helo"

or directly using -E (or --extended-regexp):

grep -E "hello|helo"

Upvotes: 2

user1766169
user1766169

Reputation: 1987

Regexp (or regex) is short for Regular Expression and means that you can grep for a specific pattern, not just a regular string. E.g. if you want to grep for all lines containing a digit you can do:

grep -e "[0-9]" <file>

Read more here: http://en.wikipedia.org/wiki/Regular_expression

Upvotes: 1

Related Questions