in reply to Clean filenames with /usr/bin/rename

Hi bsb,

The following should rename all the files in the current directory in the fashion you wish.
perl -e 'for (<*>){ my $f= $_; tr/, -/_/s; rename $f, $_}'

I hope this helps
thinker

Update Whoops, forgot the lower case. Quick fix.
perl -e 'for (<*>){ my $f= $_; tr/, -/_/s; tr/A-Z/a-z/; rename $f, $_} +'

Replies are listed 'Best First'.
Re: Re: Clean filenames with /usr/bin/rename
by bsb (Priest) on Jun 17, 2003 at 23:18 UTC
    Thanks but the program already exists and it's in Perl:
    $ head -n 4 `which rename` #!/usr/bin/perl -w # # This script was developed by Robin Barker (Robin.Barker@npl.co.uk), # from Larry Wall's original script eg/rename from the perl source.
    I just need a new improved expression that catches all stupid file names and converts them to something sensible. The original post does it ok, I'd hoped someone had a thoroughly tested expression ready to post.

      Let me try it again. See sub sanitize for the matching pattern in various s///, in the referenced program, that i consider fit the mold of unholy names on unix. You could then round up all the matching regexen to create one regex for rename.