我熟悉bash中的
shell编程,但是由于某些原因egrep -o打印只匹配的单词不起作用,并显示如下错误.
环境是ksh unix控制台在putty而不是linux或ubuntu终端……任何建议是赞赏!
终端输入&输出:
AB12 $echo "i am a boy" | grep -w "am" i am a boy AB12 $echo "i am a boy" | egrep -o "am" egrep: illegal option -- o usage: egrep [ -bchilnsv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ... AB12 $echo$ ksh: echo$: not found AB12 $echo $SHELL /bin/ksh AB12 $echo "i am a boy" | grep -o "am" grep: illegal option -- o Usage: grep -hblcnsviw pattern file . . . AB12 $
PS:类似的线程但已经尝试:Can grep show only words that match search pattern?
我假设这是一个连接到的Solaris框. Solaris的grep版本没有-o选项.所以你也可以
原文链接:https://www.f2er.com/bash/386609.html>在您的Solaris盒子上安装GNU grep(它可能已经安装在/usr/sfw / bin中,或者你可能会喜欢pkg install // solaris / text / gnu-grep);要么
>使用awk(见this SO question)
看到我的盒子:
$uname SunOS $ echo "i am a boy" | grep -o "am" grep: illegal option -- o Usage: grep -hblcnsviw pattern file . . . $ echo "i am a boy" | /usr/sfw/bin/ggrep -o "am" am