in reply to Getting files matching pattern (i.e. *.html)
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...#!/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"; } }
|
|---|
| 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 |