grep - Multi-line group capturing between braces - Ask Ubuntu
i have in file testtt
:
{it captures this! } // question: 2572410 name: question 2 ::question 2::[html] going -40 tomorrow? { can't capture this!!! why? }
when do:
grep -o '{\([^}]*\)}' testttt
it can't capture multi-line braces. modify in way capture both apppreciated!
ps. have tested given solution from: how grep multiple patterns on multiple lines? , gives following error:
grep: unescaped ^ or $ not supported -pz
you can find text file of output , file contents here
by default, grep
reads , processes single lines.
in newer versions of grep
, can use -z
option tell consider input null separated instead of newline separated; since input doesn't have null terminations, that's equivalent perl's 'slurp' mode. do
$ grep -zpo '{[^}]*}' testttt {it captures this! } { can't capture this!!! why? }
or, more perlishly, using .*?
non-greedy match (?s)
include newlines in .
$ grep -zpo '(?s){.*?}' testttt {it captures this! } { can't capture this!!! why? }
alternatively, if pcregrep
available,
$ pcregrep -mo '(?s){.*?}' testttt {it captures this! } { can't capture this!!! why? }
Comments
Post a Comment