Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: doing a search and replace on a large file

by hardburn (Abbot)
on Apr 14, 2004 at 13:12 UTC ( #345043=note: print w/ replies, xml ) Need Help??


in reply to doing a search and replace on a large file

That's a one-liner, provided your pattern is reasonably small. You don't need to open filehandles if you use perl's command line options and the shell to your advantage:

perl -lne 'print if /pattern here/' old_file.txt > new_file.txt

----
: () { :|:& };:

Note: All code is untested, unless otherwise stated


Comment on Re: doing a search and replace on a large file
Select or Download Code
Re: Re: doing a search and replace on a large file
by eXile (Priest) on Apr 14, 2004 at 14:01 UTC
    Or, if you want to overwrite the file use the '-i' cmdline option for in-place editting:
    perl -pi -e's/pattern here//g' file
    Update: reread question, you don't want to overwrite the file, so you don't want this.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://345043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2015-07-06 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (77 votes), past polls