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

Provisional solution, that is.
$ rename -v "\$_=lc;s/&/ and /g;y/()'/--/sd;s/(?:(\.)|(-)|[\W_])+/\$1| +|\$2||'_'/ge" *
Shell quoting is nasty. The unprotected perl expression is:
$_=lc;s/&/ and /g;y/()'/--/sd;s/(?:(\.)|(-)|[\W_])+/$1||$2||'_'/ge;
I took the '&' handling from here and parv's preferences for '.' then '-' then '_' when grouping but with my own (re)implementation. My test data was pretty minimal and I'd welcome improvements or even better test cases.

Brad

my @f = ( 'Godspeed - Sunshine and Gasoline.mp3', 'Pogues - Token Celtic Drinking Song.mp3', 'The Pogues - Beer, Beer, Beer (Irish drinking song).mp3', 'Hell\'s Ditch', 'One&Two.mp3', 'A!! ...--B._._.C_-___-_D-._.-E', ); + for (@f) { print; $_=lc;s/&/ and /g;y/()'/--/sd; print; s/(?:(\.)|(-)|[\W_])+/$1||$2||'_'/ge; print; }
Here's how I use it in the 'clean_name' script
#!/usr/bin/env perl # I couldn't work out how to escape this for a shell alias my $cmd = join '', split /\n/, <<'CMDS'; $_=lc;s/&/ and /g; y/()'/--/sd; s/(?:(\.)|(-)|[\W_])+/$1||$2||'_'/ge; s/^[._-]//; s/[._-]$//; CMDS system('rename','-v',$cmd, @ARGV);