[英]Sed command on Linux only matches 1, where on Solaris multiple matches are found
注意我是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並發現了在Posix / Gnu上總是貪婪的注釋並且應該使用Perl(請參閱sed中的非貪婪正則表達式匹配? )。因此我嘗試用Perl修復它,但是比起我最后遇到問題,使用“//”,“|”,在<token>之前缺少運算符,等等,因此我的帖子在這里)
通過將地址指定為//
不確定您要實現的目標。 您可能暗示它應該是文件結尾或空白行。 在前一種情況下使用$
作為地址,在后一種情況下使用/^$/
。
以下可能適合您:
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.