Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: doing a search and replace on a large file

by b10m (Vicar)
on Apr 14, 2004 at 12:48 UTC ( #345029=note: print w/replies, xml ) Need Help??

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;

All code is usually tested, but rarely trusted.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://345029]
[Corion]: Tabish: What are "tow" packages? Maybe you want to use PAR::Packer to copy them and your main program into one (ugly) script for distribution?

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-12-11 09:55 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (288 votes). Check out past polls.