tr from the command line
Michael Wittman
plug-discuss@lists.plug.phoenix.az.us
Tue, 14 May 2002 22:48:03 -0700
--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Tue, May 14, 2002 at 08:40:05PM -0400, Carl Parrish wrote:
> I've got a lot of files called *_log. I want to change them all to *.log. I *think* I want to use the tr command. Can anyone give me the syntax? my undertanding from the info and man files isn't working.
Here's another option that can get rid of all of those tedious rename
scripts altogether. I've attached a file (originally by Larry Wall)
that implements a simple but highly effective rename in Perl. Just
give a first argument that is a Perl expression that changes $_ from
the original name to the desired name. (If you didn't understand that
last sentence, dont worry.) In most cases, you'll just want to use
substitution. So, for your case:
rename.pl 's/_log$/.log/' *_log
Beware though that there's not much in terms of error checking beyond
verifying Perl syntax.
-Mike
--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="rename.pl"
#!/usr/bin/perl
# rename script examples from lwall:
# rename 's/\.orig$//' *.orig
# rename 'y/A-Z/a-z/ unless /^Make/' *
# rename '$_ .= ".bad"' *.f
# rename 'print "$_: "; s/foo/bar/ if =~ /^y/i' *
$op = shift;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
--lrZ03NoBR/3+SXJZ--