I\'m looking for a quick and easy one-liner to extract all brace-delimited text-blocks containing a search string from a text file. I\'ve just about googled myself crazy on
Here is a modified version of this gem from 'leu' (10x leu for enlighten us). This one is doing something very similarly. Extract everything between which begin with 'DEC::PKCS7[' and ending with ']!':
cat file | sed '/^DEC::PKCS7\[/{s///; :1; /\]\!$/!{N; b1;}; s///;};'
Explanation:
/^DEC::PKCS7\[/ # if current line begins with 'DEC::PKCS7[' then execute next block
{ # start block
s///; # remove all upto 'DEC::PKCS7['
:1; # label '1' for code to jump to
/\]\!$/! # if the line does not end with ']!' then execute next block
{ # start block
N; # add next line to pattern space
b1; # jump to label 1
}; # end block
s///; # remove all from ']!' to end of line
}; # end block
Notes: