http://qs321.pair.com?node_id=345029


in reply to Re: doing a search and replace on a large file
in thread doing a search and replace on a large file

Minor tweak: since the OP wants to "delete" lines that do not match a certain pattern, I'd change the unless into an if. That way, you "save" the lines that do match the pattern ;-)

open IN, "<$bigfile" or die "Can't open $bigfile: $!\n"; open OUT, ">$newfile" or die "Can't open $newfile: $!\n"; while(<IN>) { print OUT $_ if /the pattern in question/; } close OUT; close IN;
--
b10m

All code is usually tested, but rarely trusted.