unix - sed multiline remove before pattern -
hi have big log file trying xml data passed it.
i have big log file ressembles :
2016/01/01 bladh bqskjdqskldjqsdlqskdjqlskdj dazihzmkldjkdjqslkjd 2016/01/01: qsdhqsdlkqsmdjqsldjqslkdjqlskdjqslkdjqslkdjqskdjqsd 2016/01/01: qsjdqmlskdmlqskdmcxxxx [qskjd][qsdjqslkdj] payload :[<log><a>a</a> <b>b</b> <c>c</c> <id>xxxxx</id> <d>d</d> </log>]] 2016/01/01 bladh bqskjdqskldjqsdlqskdjqlskdj dazihzmkldjkdjqslkjd 2016/01/01: qsdhqsdlkqsmdjqsldjqslkdjqlskdjqslkdjqslkdjqskdjqsd 2016/01/01: qsjdqmlskdmlqskdmcxxxx [qskjd][qsdjqslkdj] payload :[<log> <a>a</a> <b>b</b> <c>c</c> <id>yyyyy</id> <d>d</d> </log>]] qskdmqlskdqlsdqlskdqlsdk qsdlkqsdlkqsdmlkqsdlk
for using
sed -n '/<start/{:start /\/end/!{n;b start};/xxxxx/p}' logfile
and getting
2016/01/01: qsjdqmlskdmlqskdmcxxxx [qskjd][qsdjqslkdj] payload :[<log><a>a</a> <b>b</b> <c>c</c> <id>xxxxx</id> <d>d</d> </log>]]
i retrieve whole xml , :
<log> <a>a</a> <b>b</b> <c>c</c> <id>xxxx</id> <d>d</d> </log>
thanks in advance
solution in txr:
@(repeat) @ (skip)payload :[<@tag>@preamble @ (collect) @middle @ (last) </@tag>]] @ (end) @ (output) <@tag> @(trim-str preamble) @ (repeat) @middle @ (end) </@tag> @ (end) @(end)
run:
$ txr extract.txr data <log> <a>a</a> <b>b</b> <c>c</c> <id>xxxxx</id> <d>d</d> </log> <log> <a>a</a> <b>b</b> <c>c</c> <id>yyyyy</id> <d>d</d> </log>
Comments
Post a Comment