Wednesday, January 05, 2005

gnu grep is -Perfect

I wanted to use grep recently and needed to grab a couple of lines using a regular expression that I knew would work in perl, but I couldn't make work in egrep functionality.

A little trolling through the man page pointed me to the -P option which provides perl like regular expression capabilities.

All of a sudden you have access to things like \d{3,6} and other perl regex niceities.

No more cat | perl -ne 'chomp($_);print "$_\n" if(/^\d{3,9}\s+\w+/);'

grep -P is perfect

0 Comments:

Post a Comment

<< Home