Wednesday, September 30, 2009

Perl one liner, backreferences, displaying only part of a line

I like this construct for searching through files in a directory and pulling out part of a line.

Just add the regular expression. The '?' designates a non-greedy expression, which means the finite statement machine will quit on the first successful match.

find . -name "*.xml" | xargs perl -ne '/(.*?)"/; print $1; print "\n";'

No comments: