Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Re: Large file processed line by line

by mirod (Canon)
on Jun 19, 2001 at 09:54 UTC ( #89553=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Large file processed line by line
in thread Large file processed line by line

You really should have tested it:

  • -e should be immediatelly followed by the script to run,
  • -p prints the current line, so you don't have to do it yourself, -n is what you want in this case.

This (tested!) script would work as:

perl -i.bak -n -e"print if(m/foo/);" foo.txt bar.txt baz.txt

From perldoc perlrun:

-n causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed -n or awk: LINE: while (<>) { ... # your program goes here } "BEGIN" and "END" blocks may be used to capture control before or after the implicit program loop, just as in awk. -p causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed: LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; } If a file named by an argument cannot be opened for some reason, Perl warns you about it, and moves on to the next file. Note that the lines are printed automatically. An error occurring during printing is treated as fatal. To suppress printing use the -n switch. A -p overrides a -n switch. "BEGIN" and "END" blocks may be used to capture control before or after the implicit loop, just as in awk.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2023-02-06 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?