gpt4 book ai didi

sed - 如果找到,如何根据模式获取特定行

转载 作者:行者123 更新时间:2023-12-04 23:22:19 26 4
gpt4 key购买 nike

我试图从一个非常大的文件中收集文件名,具体取决于特定用户,在这种情况下 windowsdom\nasarchive被发现。

我试过运行 sed -nr "/-{3,}/h; /Path\s*:/H; /windowsdom\\nasarchive\s+Allow\s+FullControl/{x;G;p}" logfilename但它不会带来任何东西。

-----------------------
Path: U:\Credit share\BI-WEEKLY CREDIT NOTES\2010\Credit status - April 21 - 2.doc


AccessToString : windowsdom\nasarchive Allow FullControl
BUILTIN\Administrators Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
BUILTIN\Users Allow ReadAndExecute, Synchronize

-----------------------
Path: U:\Credit share\BI-WEEKLY CREDIT NOTES\2009\Credit status - Sept. 23 - 59.doc


AccessToString : windowsdom\acl_1 Allow ReadAndExecute, Synchronize
windowsdom\acl_2 Allow Modify, Synchronize
windowsdom\acl_3 Allow ReadAndExecute, Synchronize
windowsdom\adm_server Allow Modify, Synchronize
BUILTIN\Administrators Allow FullControl


-----------------------
Path: U:\Credit share\BI-WEEKLY CREDIT NOTES\2010\Credit status - August 10 - 3.doc


AccessToString : windowsdom\nasarchive Allow FullControl
BUILTIN\Administrators Allow FullControl
NT AUTHORITY\SYSTEM Allow FullControl
BUILTIN\Users Allow ReadAndExecute, Synchronize



-----------------------

预期结果:
Path: U:\Credit share\BI-WEEKLY CREDIT NOTES\2010\Credit status - April 21 - 2.doc
Path: U:\Credit share\BI-WEEKLY CREDIT NOTES\2010\Credit status - August 10 - 3.doc

有人能想出如何得到预期的结果吗?

最佳答案

这可能对你有用(GNU sed):

sed -rn '/^Path:/h;/windowsdom\\nasarchive\s+Allow\s+FullControl/{g;p}' file

这将打印最后一个 Path string 当遇到所需的字符串时。

关于sed - 如果找到,如何根据模式获取特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20588593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com