lidia
lidia

Reputation: 3183

Solaris equivalent of -o option of grep on Linux

I run the following on Sun Solaris — it runs 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 is which option on Sun Solaris does the same task as the option grep -o (to match string capture) on Linux?

Upvotes: 6

Views: 4191

Answers (4)

Scott D.
Scott D.

Reputation: 9

Within Solaris, (OpenSolaris, OpenIndiana, etc.) you should use a command like this:

find . | xargs grep 'somestring'

That will get you what you are after.

Upvotes: -1

Uli Schlachter
Uli Schlachter

Reputation: 9867

Solaris grep doesn't seem to have such an option. If you just need this to run on some Solaris boxes, perhaps they have 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?

Upvotes: 3

Kilian Foth
Kilian Foth

Reputation: 14346

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

Upvotes: 1

ghostdog74
ghostdog74

Reputation: 342413

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

Upvotes: -1

Related Questions