[pm-h] File::Find and system
Russell L. Harris
rlharris at oplink.net
Tue Sep 20 14:42:18 PDT 2011
Running Linux, I need to execute various system utilities (including
"dos2unix") on multiple files in multiple directories. The file
structure is similar to the following:
foo/jan/01.txt
foo/jan/02.txt
foo/jan/03.txt
...
foo/feb/01.txt
foo/feb/02.txt
foo/feb/03.txt
...
foo/dec/01.txt
foo/dec/02.txt
foo/dec/03.txt
...
bar/jan/01.txt
bar/jan/02.txt
bar/jan/03.txt
...
bar/feb/01.txt
bar/feb/02.txt
bar/feb/03.txt
...
bar/dec/01.txt
bar/dec/02.txt
bar/dec/03.txt
...
foobar/jan/01.txt
foobar/jan/02.txt
foobar/jan/03.txt
...
foobar/feb/01.txt
foobar/feb/02.txt
foobar/feb/03.txt
...
foobar/dec/01.txt
foobar/dec/02.txt
foobar/dec/03.txt
...
Regrettably, not all Linux utilities have a recursive option, and I do
not wish to take the time to re-write and debug functions which
already are available as a standard utilities.
A very tedious approach would be to "cd" to "foo/jan/" and run
"dos2unix *.txt", then "cd" to "foo/feb/" and run "dos2unix *.txt",
etc.
I know that a Perl script can automate the process. I just discovered
the Perl "File::Find" module and the Perl "system" function, and now I
am perusing the O'Reilly Perl books, trying to understand how to
combine the two into a script.
Afterward, I need to do involved search-and-replace processing on
these files which cannot be handled with system utilities. I
previously have used Perl scripts for similar tasks, but never on a
multi-level directory.
So, learning how to run system utilities with "File::Find" appears to
me to be the logical first step.
RLH
More information about the Houston
mailing list