in reply to help on stripping out extra extensions

look at 'rename', there are two versions I'm aware of one which uses perl regexes and one which doesn't :). For the one with perl regexes something like 's/\.html$//' as the first arg and the files as the second+ arg should work. for the other version something like 'rename '.html' '' *.html' should fix it up, just be aware that that version replaces . *first* occurence.. look at the man page on you local machine to determine your version and find more options

and a pure perl solution

perl -e 'foreach (@ARGV) {next unless -f && /\.html\.html$/;($new = $_) =~ s/\.html$//;die $new if -f $new;rename $_, $new;}' *.html

I'm sure that's longer than it needs to be... :( hehe. That should do it, *note that it is untested.

Replies are listed 'Best First'.
Re^2: help on stripping out extra extensions
by Aristotle (Chancellor) on Jun 21, 2003 at 12:23 UTC
    Careful. Your first two solutions will happily remove a correct, lone .html. Rather, you should replace multiple occurences with a single one, as you (almost) did in your oneliner:
    # perl rename rename 's/(?:\.html){2,}$/.html/' *.html
    # unix rename rename .html.html .html *.html
    Your oneliner can be shortened by not checking if a substitution will be successful first; the substitution simply fails if no match is found. Untested:
    # perl oneliner perl -e '-f && ($a = $_) =~ s/(?:\.html){2,}$/.html/ && -e $new ? warn + $_ : rename $_, $new for @ARGV' *.html

    Makeshifts last the longest.