Linux上的Sed命令仅匹配1,在Solaris上找到多个匹配项

时间:2014-04-25 09:26:45

标签: regex linux sed

请注意我是SED的初学者。

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

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

(示例clearcase输出:

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(参见Non greedy regex matching in sed?)。因此,我试图修复它与Perl一起使用,但是在最后使用&#34; //&#34;,&#34; |&#34;,在&lt; token&gt;之前缺少运算符时遇到问题。 ,等等,因此我的帖子在这里)

1 个答案:

答案 0 :(得分:2)

通过将地址指定为//,不确定您要尝试实现的目标。您可能暗示它应该是文件结尾或空白行。在前一种情况下使用$作为地址,在后一种情况下使用/^$/

以下内容可能适合您:

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.