From: Chris on
Hi
I have found out I cannot use egrep to grep for multiple strings with
exact match (-w) option in grep.

So for example to grep a whole string:

grep "\<PCRF peer disconnected\>" gives different results to

egrep "\<PCRF peer disconnected\>"

I need to use egrep to combine "or" functionality.

Anyone seen this before? and is there a workaround?


From: Darren Dunham on
On Apr 6, 4:10 am, Chris <cconnel...(a)lycos.com> wrote:
> Hi
> I have found out I cannot use egrep to grep for multiple strings with
> exact match (-w) option in grep.

Can you give a complete example? A source string, your grep/egrep
commands, and your expectation of what should be output?

--
Darren


From: Voropaev Pavel on
man egrep

....
/usr/bin/egrep
The /usr/bin/egrep utility accepts full regular expressions
as described on the regexp(5) manual page, except for \( and
\), \( and \), \{ and \}, \< and \>, and \n
....
From: Chris on
On Apr 7, 9:53 am, Voropaev Pavel <voropa...(a)gmail.com> wrote:
> man egrep
>
> ...
> /usr/bin/egrep
>      The /usr/bin/egrep utility accepts full regular  expressions
>      as described on the regexp(5) manual page, except for \( and
>      \), \( and \), \{ and \}, \< and \>, and \n
> ...

Here is an example

So does that mean /urs/bin/egrep cannot do exact match (e.g. like grep
-w)

[psv01:/root] # grep -w "localhos" /etc/hosts

[psv01:/root] # grep -w "localhost" /etc/hosts
::1 localhost
127.0.0.1 localhost

I want to do the same using "egrep" because I want to do something
like
egrep -w "localhost|loghost" /etc/hosts

in one command.

I have tried using many combinations in grep/egrep to achieve this.

From: Wolfgang Ley on
Hi,

Chris wrote:
> Here is an example
>
> So does that mean /urs/bin/egrep cannot do exact match (e.g. like grep
> -w)
>
> [psv01:/root] # grep -w "localhos" /etc/hosts
>
> [psv01:/root] # grep -w "localhost" /etc/hosts
> ::1 localhost
> 127.0.0.1 localhost
>
> I want to do the same using "egrep" because I want to do something
> like
> egrep -w "localhost|loghost" /etc/hosts
>
> in one command.
>
> I have tried using many combinations in grep/egrep to achieve this.
>

The egrep command does not provide the -w option.
The /usr/bin/egrep command does not provide the \< and \> options.

So the solution is to use /usr/xpg4/bin/egrep to get the full
regular expressions, e.g.
# /usr/xpg4/bin/egrep '(\<localhost\>|\<loghost\>)' /etc/hosts

See the manpage of egrep for more details.

Bye,
Wolfgang.