Thursday, January 28, 2016

multi line replacement using perl

I want to find all the files in a dir which has the below multi-line pattern
// *
// *
 and replace with 
// *

Typically we might end up in situation like this.. So instead of  writing a script for this, we can make life easier with perl one liner...

perl -0777 -i -pe 's/\/\/ \*\s*\n\/\/ \*\s*\n/\/\/ *\n/g' *

-pie is your standard "replace in place" command-line sequence, and -0777 causes perl to slurp files whole.

No comments:

Post a Comment