我正在筛选一个日志文件,并根据类别类型将其分为多个部分。我在一个类别中工作:
sed -e '/Associating reconciliation identity to/{N;N;d}' source.log > destination.txt
当我搜索一个不同的字符串并试图删除该行,以及随后的7行时,我遇到了一个问题。我不是100%
sed
是最好的工具,但我还没有得到awk
的工作。根据上面的例子,我认为这应该有效:sed -e '/Found multiple matches (instances) for class/{N;N;N;N;N;N;N;N;d}' source.log > destination.txt
有更好的办法吗?
请求添加:
源.log
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7938 */ Found multiple matches (instances) for class <Software.Class> in look-up dataset <Category>
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7939 */ for qualification <'Name' != $\NULL$ AND 'Name' = $Name$> of group <Job-ID> with values
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7939 */ < Name = software.example >
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7939 */ < RelLeadClassId = NULL >
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7939 */ < RelLeadInstanceId = NULL >
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7939 */ < RequestId = 00000000000|00000000000|000000000000 >
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7939 */ < Secondary_UID = NULL >
<ERROR > <TID: 140100592498432> /* Wed Aug 29 2018 05:18:20.7939 */ < TokenId = HashToken87hnUIKW22er4xbs78== >
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ Found multiple matches (instances) for class <Software.Class> in look-up dataset <Category>
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ for qualification <'Name' != $\NULL$ AND 'Name' = $Name$> of group <Job-ID> with values
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ < Name = software.version >
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ < RelLeadClassId = NULL >
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ < RelLeadInstanceId = NULL >
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ < RequestId = 000000000|000000000000|000000000000>
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ < SERVICE_NOW_UID = NULL >
<ERROR > <TID: 140100593551104> /* Wed Aug 29 2018 05:18:20.7946 */ < TokenId = HashTokenHHK72nsyUIOI92bYH== >
最佳答案
试试这个:
sed -e '/<search string here>/,+7d' source.log > destination.txt
关于bash - sed或awk删除匹配正则表达式的行以及以下行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52083687/