-2

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. 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)? 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
}
DyslexicHobo
  • 17
  • 1
  • 1
  • 6
  • Can you include an example of the output that's being parsed? A Bash-ism could do this without a separate process. – l3l_aze Sep 14 '20 at 22:15
  • 1
    will `{` and `}` ever be present on the same line? – jeremysprofile Sep 14 '20 at 22:15
  • @jeremysprofile No. The braces will always be on lines by themselves. – DyslexicHobo Sep 14 '20 at 23:37
  • Yes, it's straightforward in sed. But we ask that you show your own efforts first. – Beta Sep 16 '20 at 00:12
  • 1
    Does this answer your question? [How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?](https://stackoverflow.com/questions/38972736/how-to-print-lines-between-two-patterns-inclusive-or-exclusive-in-sed-awk-or) – Ravi Saroch Sep 17 '20 at 08:53

1 Answers1

1

Using multiple sed

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

Using Single sed

sed -n '/{/,/}/{/{/!{/}/!p}}' InputFile
Ravi Saroch
  • 934
  • 2
  • 13
  • 28