solaris + egrep command syntax not work

1

my target is to match snmpmanager string from /etc/hosts file in Solaris machine

I don’t get any match output from the following command (but snmpmanager already defined in host file) why??

 egrep -i '(^|[[:space:]])snmpmanager($|[[:space:]])'  /etc/hosts

my host file

 10.170.10.5      loghost
 10.170.10.61   Master SyslogSer vip Tcc NtpServer1 NtpServer2 snmpManager snmpManagerPA1 snmpManagerPA2

I also tried the following but without success -:(

   egrep -i '(^|[\s])snmpmanager($|\s])'  /etc/hosts
   egrep -i '(^|[\t])snmpmanager($|\t])'  /etc/hosts

Eytan

Posted 2012-02-08T17:18:11.820

Reputation: 47

Answers

1

Unfortunately Solaris' regular expression parsing is limited at what it can do.

You can try doing:

egrep '(^| )snmpmanager($| )' /etc/hosts

But I would simply use PERL and \b tags.

Karlson

Posted 2012-02-08T17:18:11.820

Reputation: 2 163

I find the solution for solaris its - grep -iwc snmpManager (only need to add w flag) – Eytan – 2012-02-08T17:54:41.650

1@eytan if your solution works, its good to have you make it an answer, and accept it, so the question is closed out – Rich Homolka – 2012-02-08T18:03:20.400