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.)
| |