简体   繁体   English

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

[英]Sed command on Linux only matches 1, where on Solaris multiple matches are found

note I'm a beginner with SED. 注意我是SED的初学者。

We make use of sed-command which looks in the output of a clearcase command and obtains the names of users with a view: 我们使用sed-command查看clearcase命令的输出,并获取具有视图的用户的名称:

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

(Example clearcase output: (示例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

)

On Solaris it will output: 在Solaris上它将输出:

nemelis nemelis

otheruser otheruser

But on (Redhat-)Linux only the first name is given. 但是在(Redhat-)Linux上只给出了第一个名字。

(Note: I've looked on Stackoverflow and found comments that Sed is always greedy on Posix / Gnu and that Perl should be used (see Non greedy regex matching in sed? ). Thus I've tried to fix it with Perl, but than I ran into a forrest of problems with the p at the end, using "//", "|", missing operator before < token >, etcetera, hence my post here) (注意:我查看了Stackoverflow并发现了在Posix / Gnu上总是贪婪的注释并且应该使用Perl(请参阅sed中的非贪婪正则表达式匹配? )。因此我尝试用Perl修复它,但是比起我最后遇到问题,使用“//”,“|”,在<token>之前缺少运算符,等等,因此我的帖子在这里)

Not sure what you're trying to achieve by specifying the address as // . 通过将地址指定为//不确定您要实现的目标。 You probably imply that it should be end of file or a blank line. 您可能暗示它应该是文件结尾或空白行。 Use $ as the address in the former case, and /^$/ in the latter. 在前一种情况下使用$作为地址,在后一种情况下使用/^$/

The following might work for you: 以下可能适合您:

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

From the manual: 从手册:

$

  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. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM