【问题标题】:Grep lines for multiple words and the line ending, and then replace line ending if matchedGrep 多个单词的行和行尾,如果匹配则替换行尾
【发布时间】:2021-03-26 17:14:15
【问题描述】:

我需要为包含多个可能单词且以“=1”结尾的行生成一个长文本文件,然后用相同的文本替换该行,但将“=1”更改为“=0”。

我正在使用 BBEdit。

到目前为止,我已经找到了包含所需匹配且也以 1 结尾的行:

^(.*test|.*disabled|.*inactive|.*server).*(=1)

但我无法成功更换。

以下是文件中的一些示例文本行:

OU>2020,OU>Disabled Accounts,DC>net,DC>example,DC>com=1
OU>Distribution Groups,DC>net,DC>example,DC>com=1
OU>Exchange Servers,DC>net,DC>example,DC>com=1
CN>Users,DC>net,DC>example,DC>com=1
OU>Test Servers,OU>Servers,OU>ABC,DC>net,DC>example,DC>com=1

例如,上面的第一行会将其 =1 更改为 =0,例如:

OU>2020,OU>Disabled Accounts,DC>net,DC>example,DC>com=0

其他匹配将遵循该模式。

【问题讨论】:

    标签: grep bbedit


    【解决方案1】:

    在玩了更多之后,这似乎有效:

    查找:

    (^.*(test|disable|inactive|server).*)(=1)$
    

    替换:

    \1=0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-30
      • 2017-06-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      相关资源
      最近更新 更多