Solaris + grep syntax in solaris

grepsolaris

my target is to match Exactly the string snmpmanager from hosts file on solaris & linux

the following command work on Linux (red-hat 5.1) but not for SunOS , please advice how to fit the syntax to solaris?

example from solaris OS

   grep -icE '(^|[[:space:]])snmpmanager($|[[:space:]])' /etc/hosts
   grep: illegal option -- E

after I fixed it to

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

but I don’t get any match output (but snmpmanager already defined in host file) ??

my host file

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

Best Answer

I don't think the standard Solaris (e)grep understands the [[:space:]] syntax so you would have to use something like

egrep -i (^| |<-TAB->)snmpmanager($| |<-TAB->)

where <-TAB-> is Ctrl-VTab

If you use /usr/xpg4/bin/egrep then it works as expected.

/usr/xpg4/bin/egrep -i '([[:space:]])snmpmanager($|[[:space:]])'  /etc/hosts
Related Topic