[PLUG] Re: script to rename files?
Randal L. Schwartz
merlyn at stonehenge.com
Sat Apr 9 16:28:52 UTC 2005
>>>>> "Michael" == Michael D Harris <michael.harrisdmd at comcast.net> writes:
Michael> Since I do not have enough experience with scripts in bash,
Michael> can someone give me a script to read file names in, remove
Michael> spaces, and save the file without the spaces. Preferable
Michael> removing the original file?
perl -e 'for (@ARGV) {$o = $_; tr/ /_/; rename $o, $_ unless -e}' *
Basically, for the filenames listed on the command line,
save the old name as $o, replace spaces with underscores, and
rename the old name to the new name unless the new name exists.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <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!
More information about the PLUG
mailing list