regex - User defined Regular expression pattern match, how to? -
i got complicated file having contents as:
aaa { "(bbb|kkk)" { b_1 abc; b_2 bcd; b_3 efg; b_4 xyz; } ccc { c_1 cbc; c_2 dcd; } } ddd { eee { e_1 ebc; e_2 fcd; } "(fff|lll|mmm|nnn)" { f_1 gbc; f_2 hcd; } } ggg { g_1 ibc; } hhh { iii { jjj { j_1 jbc; j_2 kbc; } } }
i want using awk or tools output (just take example)
f_1 = gbc g_1 = ibc j_1 = jbc
my question is: how define regular expression pattern match, first, search key word fff
, output contents between closest bracelets {
, }
?
f_1 gbc; f_2 hcd;
and contents can further piped , using grep
can value gbc
item f_1
.
anyone knows how it?
this allow "define regular expression pattern match, first, search key word fff, output contents between closest bracelets { , }":
$ gawk -v rs='\0' '{ print gensub(/.*\yfff\y[^{]+{[[:space:]]*\n([^}]+)\n[[:space:]]*}.*/,"\\1","") }' file f_1 gbc; f_2 hcd;
do not pipe output grep. whatever want can done within single awk call.
Comments
Post a Comment