views:

57

answers:

3

hi

I run the following on sun Solaris (its run OK on Linux) but not on sun Solaris

name="(WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))"
echo $name | grep -o "(WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT =  10234))"
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .

my question which the same option on sun Solaris as the option grep -o (to match string capture)

lidia

A: 

then you can use nawk the "old school" way. Go over each word and check against your patterns

nawk '{
  for(i=1;i<=NF;i++){
      if($i == "your pattern") {
           print $i
      }
  }
}' file
ghostdog74
A: 

Sun's^W^WOracle's grep doesn't do that. You need to download the GNU grep version, preferably from sunfreeware.com.

Kilian Foth
+1  A: 

Solaris grep doesn't seem to have such an option. If you just need this to run on some solaris boxes, perhaps they got GNU grep installed? (E.g. this one has it under /usr/local/gnu/bin/grep).

If you need this to run under any solaris, you cannot use grep. Perhaps sed and awk can be used?

Uli Schlachter