简体   繁体   English

从 tail -f 只打印花括号之间的行

[英]Print only lines between curly braces from tail -f

I have a script that reads several debug logs, appends it to a temp file, then does a tail -f on the debug file so that we can monitor debug events in a single window and easily see when a user action induces an event.我有一个脚本,它读取多个调试日志,将其附加到临时文件,然后在调试文件上执行tail -f ,以便我们可以在单个窗口中监视调试事件,并轻松查看用户操作何时引发事件。 There is a bunch of metadata also written to these debug logs that I don't want included in the monitor script's output.还有一堆元数据也写入这些调试日志,我不希望将它们包含在监视器脚本的输出中。

Is there a way I can use sed or awk to print only data that's contained within curly braces (including the curly braces)?有没有一种方法可以使用sedawk仅打印包含在花括号(包括花括号)中的数据? The data within braces can, and always does, span multiple lines.大括号内的数据可以并且总是跨越多行。

Data might look like this:数据可能如下所示:

DON'T PRINT THIS DATA:!@#%$%^
DON'T "!@#()*& PRINT THIS DATA EITHER
}
DON"T PRINT THIS
{
PRINT THIS DATA BLOCK
AND THIS DATA
AND THIS LINE TOO:!@#(*&
}
DONT:!@# \/PRINT THIS
{
BUT PRINT THIS
}

Using multiple sed使用多个 sed

sed -n '/{/,/}/p' InputFile | sed '/^{/d' | sed '/^}/d'

Using Single sed使用单个 sed

sed -n '/{/,/}/{/{/!{/}/!p}}' InputFile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM