Reputation: 3183
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
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
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
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
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