[pm-h] File::Find and system
Todd Rinaldo
toddr at cpanel.net
Tue Sep 20 20:02:39 PDT 2011
Perl can do this but if you're just talking dos2unix and equally simple commands, you can go the shell route on this one...
$> for file in (foo|bar|foobar)/*/*.txt; do dos2unix $file; done
Add more commands if you like.
On Sep 20, 2011, at 4:42 PM, Russell L. Harris wrote:
> 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
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/
Todd Rinaldo
toddr at cpanel.net
----------------------------------------------------
cPanel Conference 2011-
Automation Bootcamp
Register at bootcamp.cpanel.net
Discount Code: learn4free (FREE!)
More information about the Houston
mailing list