>>>>> "Wijaya" == Wijaya Edward <[EMAIL PROTECTED]> writes:
Wijaya> Hi all,
Wijaya> I have a snippet that rename files from:
Wijaya> "sth.txt.out" into
Wijaya> "sth.out"
Wijaya> Now I am really curious how can I make this
Wijaya> oneliner "even shorter":
Wijaya> $ perl -e '
Wijaya> for(glob ("*.txt.out")){
Wijaya> $out = $_;
Wijaya> $out =~ s/\.txt(\.out)/\.out/;
Wijaya> rename ($_,$out);
Wijaya> }'
Wijaya> Hope to hear from you again.
perl -e '($n = $_) =~ s/\.txt(\.out)$/$1/ and rename $_, $n for @ARGV' *
This is unsafe (as yours was) because a file "foo.txt.out" will be renamed
over the top of an existing "foo.out". To protect that, add this:
perl -e '($n = $_) =~ s/\.txt(\.out)$/$1/ and not -e $n and rename $_, $n for
@ARGV' *
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>