Solaris equivalent of -o option of grep on Linux

Issue

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?

Solution

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?

Answered By – Uli Schlachter

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published