Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: A fast way to do this?

by perlfan (Vicar)
on Jul 14, 2014 at 14:08 UTC ( [id://1093556]=note: print w/replies, xml ) Need Help??


in reply to Re: A fast way to do this?
in thread A fast way to do this?

This is sort of the third option, but there is no reason to shell out to grep - let alone grep then pipe to wc. Look at grep's "-v" and "-c" options.

Replies are listed 'Best First'.
Re^3: A fast way to do this?
by sundialsvc4 (Abbot) on Jul 14, 2014 at 15:39 UTC

    Sometimes a handy approach is to use a command like grep to quickly identify files that need to be processed, then to pipe that to xargs (possibly using the -P numberOfProcesses option) to execute “a very simple command” against each of them.   In this case, you are looking for, say, /^\s*^#/ or something like that.   (“At start-of-line, zero or more whitespace characters followed by a character that is not a hashmark.”)

    The complexities of deciding whether to invoke a command, and against which files, has been pushed out to the Shell, which invokes the specified command (with a filename as a parameter) only on those files which match the criteria sought.   Of course, the program should not blindly assume that it was invoked under the correct conditions ... it should check ... but even so, this is a very powerful approach that is applicable in a lot of situations.

    (After so-many years of pretending that an CP/M-era shell was good enough, Microsoft finally came up with PowerShell, which is useful for these things also.   Although it is not, of course, compatible with anyone else.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found