in reply to Getting files matching pattern (i.e. *.html)

My version of this wheel:
#!/usr/bin/perl -w use strict; my $cmd = shift; while (my $filename = shift) { # Perform operation to new file. Exit on error. # TODO: On error, report command that caused problem and the result +ing # error message before dying. die if `$cmd $filename 2>&1 >$filename.new`; # If the output is different than the input, replace the old version + with # the new one. If nothing was changed, discared the new version and + leave # the old one untouched. if (`diff $filename.new $filename`) { rename "$filename.new", $filename; } else { unlink "$filename.new"; } }
I call it 'doall' as in doall "sed s/oldtext/newtext/g" *.html . A bit more flexible than what you appear to be looking for, but, if you hardcode $cmd to your sed command instead of reading it from the command line...

Replies are listed 'Best First'.
Re: Re: Getting files matching pattern (i.e. *.html)
by schnarff (Acolyte) on May 13, 2002 at 18:51 UTC
    Wow! I'm overwhelmed by the positive response here. I'm going to be sorting through these methods tonight and figuring out which one is the best. I'm sure one of them will work nicely. :-)

    Thanks for all of your help.

    Alex Kirk