Solaris 相当于 Linux 上 grep 的 -o 选项
我在 Sun Solaris 上运行以下命令 - 它在 Linux 上运行正常,但在 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 . . .
我的问题是 Sun Solaris 上的哪个选项与选项 grep -o
执行相同的任务(以匹配字符串)捕获)在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Solaris grep 似乎没有这样的选项。如果您只需要在某些 Solaris 机器上运行它,也许它们安装了 GNU grep? (例如,这个位于
/usr/local/gnu/bin/grep
下)。如果您需要在任何 Solaris 下运行它,则不能使用 grep。也许可以使用 sed 和 awk ?
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?
Sun 的^W^WOracle 的
grep
不这样做。您需要下载 GNU grep 版本,最好从 sunfreeware.com 下载。Sun's^W^WOracle's
grep
doesn't do that. You need to download the GNU grep version, preferably from sunfreeware.com.那么你可以使用“老派”方式的 nawk 。仔细检查每个单词并检查你的模式
then you can use nawk the "old school" way. Go over each word and check against your patterns
在 Solaris 中(OpenSolaris、OpenIndiana 等),您应该使用如下命令:
这将得到您想要的结果。
Within Solaris, (OpenSolaris, OpenIndiana, etc.) you should use a command like this:
That will get you what you are after.