相关讨论
请问一下在aix里面,怎么截取/etc/inittab里面的所有路径 ?在linux下我用ont color="red">grepont> -o就可以截出来,但是ksh的 ont color="red">grepont>没有-o的选项,请高人指点。
by
su8610
-
AIX
-
2013-08-26 13:50:40 阅读(7381) 回复(2)
在linux中使用ont color="red">grepont> -o参数可以获得配置的字符串,如:
echo test20080505test | ont color="red">grepont> -o '[0-9]\{8\}'
输出20080505
现在有一个shell需要在linux和AIX上运行,其中就用到了ont color="red">grepont> -o
这个参数,但是在AIX下ont color="red">grepont>命令是没有-o这个参数的,有没有什么
方法可以实现-o参数的效果并且能够兼容linux和AIX
小弟对-o的理解不是很明白不是说只显示匹配的吗
那我的一个文本
ab
aab
aaab
aaaab
如果ont color="red">grepont> -o "aa" 预想的输出应该是
aa
aa
aa吧 但为什么是
aa
aa
aa
aa呢
本帖最后由 newoz 于 2014-01-23 12:24 编辑
也就是说,我想用sed命令实现 ”ont color="red">grepont> -o“ (only match) 的效果。
因为一行里有好几个匹配的需要输出。 比如:[code]afoe=test1 afoo=test2 afoo=test3 afoe=test4 afoo=test5[/code]我只想要 afoo=后面的内容。[code]
test2
test3
test5
[/code]如果可以的话,因为该行有可能被分割(我也不确定会在哪里被换行了),我有该如何得到结果。[code]afoe=test1 afoo=test2 afoo=tes
...
by
newoz
-
Shell
-
2014-01-28 12:16:47 阅读(9507) 回复(17)
by
小木虫子
-
Shell
-
2009-08-07 15:56:31 阅读(4018) 回复(3)
参见:
wingger大姐之shell基础八:文本过滤工具
第六楼--寂寞烈火--GNU的ont color="red">grepont>,才有-o选项,很经典的~,我也最爱用 8)。
又见http://bbs.chinaunix.net/thread-1087859-1-1.html 之第十四楼--woodie--充一点,ont color="red">grepont>的缺省是匹配了就输出整行,除非你用了-o选项,所以ont color="red">grepont> '...'会显示所有包含三个字符以上字符的行。
[quote]
[root@rhel shell]# cat ont color="red">grepont>02
A
AB
ABC
ABCD
ABCD1234
.A1
baaab[/quote]
[root@rhel shell]# gr...
ont color="red">grepont>:
-o, --only-matching
Show only the part of a matching line that matches PATTERN.
例:
$cat a.txt
abcdefaaBIG1GUNjjjjssskfBIG2GUNjldskjld
$ont color="red">grepont> -o "BIG[0-9]GUN" a.txt
BIG1GUN
BIG2GUN
$awk '{?}' a.txt
awk的代码应该怎么写?
[ 本帖最后由 auser 于 2007-9-14 09:21 编辑 ]
by
auser
-
Shell
-
2007-09-14 15:20:40 阅读(2019) 回复(6)
[0-9]* 0个或多个,只匹配0个。
[0-9]\+ 1个或多个,却匹配多个。
[root@test9 root]# echo sdgasdg124asdf | ont color="red">grepont> -o '[0-9]*'
[root@test9 root]# echo sdgasdg124asdf | ont color="red">grepont> -o '[0-9]\+'
124
[root@test9 root]# echo sdgasdg124asdf | ont color="red">grepont> -o '[0-9]*'
[root@test9 root]# ont color="red">grepont> --version
ont color="red">grepont> (GNU ont color="red">grepont>) 2.5.1
Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the ...
如下有这样的文本:
xxxxxxxxxxxxxRulexxxxx,xxxxxxxxxxx
xxxxxxxxxxxxxRulexx,xxxxxxxxxxx
xxxxxxxxxxxxxRulexxxx,xxxxxxxxxxx
xxxxxxxxxxxxxRulexxx,xxxxxxxxxxx
xxxxxxxx都是一些不定的字符,其中不一定有空格
我想提出Rule到逗号的字符
如果用ont color="red">grepont>的话,可以是这样
ont color="red">grepont> -o 'Rule[^,]*'
请问一下用awk可以实现这个功能吗?
谢谢!
[ 本帖最后由 sosogh 于 2006-8-8 09:29 编辑 ]