regex - Multiline grep to find variable (constructor) definitions recursively -
how can create multiline grep across files inside directory prints out string in between both patterns including patterns themselves?
i tried use several variants, i'm kind of stuck regexp matching multiple lines.
grep -rpzo "var class = (.*) \};" ./ grep -rpzo "var class = function\(\{(.*)\};" ./
the grep command should files recursively , print out contents in between (and including) "var class = " , first "};" occurs after it, might after several line breaks. possible using grep (and not pcregrep)?
the first pattern definition of javascript function works fine, that's i'm stuck:
grep -rpzo "var class = function\((.*)\)\s\{" ./
an example definition of content should matched (to try out things more easily):
var class = function(data, game) { var settings = lychee.extend({}, data); this.foo = { x: 0, y: 0, z: 0 }; this.setfoo(settings.foo); lychee.game.bar.call(this, settings); settings = null; };
or use gawk!
{ if( $0 ~ /\{/ ) cbo++; if( $0 ~ /\}/ ) cbo--; if( cbo == 1 && $0 ~ "^([[:space:]]?+)(.+)([[:space:]]+)\\{$" ) rec=1 if( rec == 1 ) buff = ( buff ? buff "\n" : "" ) $0 if( cbo == 0 ) rec=0 } end { if( cbo == 0 ) print buff else print "dude funkey goes on ur input... " cbo " brackets left open!" }
example: http://pastebin.com/ttchbpvm
Comments
Post a Comment