Linux上的sed命令只匹配1,在Solaris上find多个匹配项

注意我是SED的初学者。

我们利用sed-command在clearcase命令的输出中查找并获取具有视图的用户的名称:

<clearcase output> | sed -n "/Development streams:/,// s/[^ ]* *Views: *\([^_ ]*\)_.*/\1/p" 

(清除输出示例:

 Project: project:xx0.0_xx0000@/xxxx/xxxxx_xxxxxxxx0 Project's mastership: XXXXXXXXX@/xxxx/xxxxx_xxxxxxxx0 Project folder: folder:XX0.0@/xxxx/xxxxx_xxxxxxxx0 (RootFolder/Xxxxxxxx/XX0.0) Modifiable components:component:00000000000@/xxxx/xxxxxx_xxxxxxxx0 component:xxxxxxx_xxxxxxx@/xxxx/xxxxxx_xxxxxxxx0 component:xxxxxxxxxxxxxx_x@/xxxx/xxxxxx_xxxxxxxx0 component:xxxxx@/xxxx/xxxxxx_xxxxxxxx0 component:xxxxxx_xxxxxxxxxxx@/xxxx/xxxxxx_xxxxxxxx0 Integration stream: stream:xx0.0_xx0000_integration@/xxxx/xxxxx_xxxxxxxx0 (FI: nemelis) Integration views: olduser_xx0.0_xx0000_int - Properties: dynamic ucmview readwrite nshareable_dos nemelis_xx0.0_xx0000_int - Properties: dynamic ucmview readwrite nshareable_dos otheruser_xx0.0_xx0000_int - Properties: dynamic ucmview readwrite nshareable_dos Development streams: stream:nemelis_xx0.0_xx0000@/xxxx/xxxxx_xxxxxxxx0 [unlocked] - No rebase or delivery is pending. Views:nemelis_xx0.0_xx0000 stream:otheruser_xx0.0_xx0000_streamidentifier@/xxxx/xxxxx_xxxxxxxx0 [unlocked] - No rebase or delivery is pending. Views:otheruser_xx0.0_xx0000_streamidentifier 

在Solaris上它将输出:

nemelis

otheruser

但在(Redhat)Linux上,只有第一个名字给出。

(注意:我查看了Stackoverflow,发现Sed总是在Posix / Gnu上贪婪,应该使用Perl(请参阅sed中的非贪婪正则expression式匹配? ),所以我试图用Perl来修复它,但是比我遇到了最后的问题,使用“/ /”,“|”,<token>之前缺less运算符等,因此我的职位在这里)

不知道你想通过指定地址为/ /来实现。 你可能暗示它应该是文件结尾或空白行。 前者使用$作为地址,后者使用$ /^$/

以下内容可能适用于您:

 sed -n "/Development streams:/,$ s/[^ ]* *Views: *\([^_ ]*\)_.*/\1/p" 

从手册:

$

  This address matches the last line of the last file of input, or the last line of each file when the `-i' or `-s' options are specified.