如何修复awk在多条件语句中打印同一行两次?

如何修复awk在多条件语句中打印同一行两次?,awk,Awk,我有一个如下所示的日志文件: Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:115 DEBUG: ClassNumberOne viewControllers: ( "<UINavigationController: 0x105031a00>", "<UINavigationController: 0x10505ba00>", "<UI

我有一个如下所示的日志文件:

Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:115 DEBUG: ClassNumberOne viewControllers: (
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
)
Jun 29 16:46:13 someline that should not be captured
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:151 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 someline that should not be captured
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:152 DEBUG: ClassNumberOne viewControllers: {
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
}
Jun 29 16:46:13 someline that should not be captured
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:153 DEBUG: ClassNumberTwo ARG2 2
我的预期输出与输入相同,不包括不相关的行,如Jun 29 16:46:13 someline,这篇文章顶部提供了不应捕获的行,但是我得到了一个单行的副本:

Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:115 DEBUG: ClassNumberOne viewControllers: (
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
)
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:151 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:151 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:152 DEBUG: ClassNumberOne viewControllers: {
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
}
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:153 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:153 DEBUG: ClassNumberTwo ARG2 2
你知道怎么解决这个问题吗?谢谢。

您可以使用此awk:

您可以使用此awk:


我编辑了这篇文章,你是对的,实际的日志包含更多不包含调试关键字的脏日志。好的,我已经根据Ed的有用评论和你的编辑更新了答案。我编辑了这篇文章,你是对的,实际日志包含更多不包含调试关键字的脏日志。好的,我已经根据Ed的有用评论和您的编辑更新了答案。
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:115 DEBUG: ClassNumberOne viewControllers: (
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
)
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:151 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:151 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:152 DEBUG: ClassNumberOne viewControllers: {
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
}
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:153 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:153 DEBUG: ClassNumberTwo ARG2 2
awk '/DEBUG:/{print; f = /[({]$/; next}; f; /^[)}]/{f = 0}' file.log
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:115 DEBUG: ClassNumberOne viewControllers: (
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
)
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:151 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:152 DEBUG: ClassNumberOne viewControllers: {
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
}
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:153 DEBUG: ClassNumberTwo ARG2 2
$ awk 'f{print; if (/^[)}]/) f=0} /DEBUG:/{if (/[({]$/) f=1; print}' file
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:115 DEBUG: ClassNumberOne viewControllers: (
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
)
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:151 DEBUG: ClassNumberTwo ARG2 2
Jun 29 16:46:13 iPhone SomeThing[MULTILINE] <Notice>: [AppName] file.x:152 DEBUG: ClassNumberOne viewControllers: {
    "<UINavigationController: 0x105031a00>",
    "<UINavigationController: 0x10505ba00>",
    "<UINavigationController: 0x10486fe00>",
    "<UINavigationController: 0x105052600>",
    "<UINavigationController: 0x105065c00>"
}
Jun 29 16:46:13 iPhone SomeThing[SINGLE LINE] <Notice>: [AppName] file.x:153 DEBUG: ClassNumberTwo ARG2 2