Wednesday, January 6, 2010

Perl multiline search/replace

Quick perl program to do a multi-line search and replace.

open(INPUT,"<$ARGV[0]") or die;
$/ = "%%\n";

$theFile=<INPUT>;
#print $theFile;
close(INPUT);

#$theFile =~ s# \true\<\/optional\>\n##ig ;
$theFile =~ s# \<\/dependency\># \true\<\/optional\>\n \<\/dependency\>#ig;

open(OUTPUT,">$ARGV[1]") or die;
print(OUTPUT $theFile);
close(OUTPUT);

No comments: