[PLUG] rename not working as expected

Dick Steffens dick at dicksteffens.com
Thu Aug 4 23:49:37 UTC 2016


On 08/04/2016 04:35 PM, Rich Shepard wrote:
>     According to man rename:
>
> rename .htm .html *.htm
>
> will fix the extension of your html files.
>
>     So, I expect that
>
> rename .JPG *.jpg
>
> will change the extension to lower case. It doesn't:
>
> rename: not enough arguments
>
> And, 'rename *.JPG *.jpg' produces the same error message.
>
>     I've done this before and do not see what I'm doing incorrectly this time.
> Perhaps it's the heat today but fresh eyeballs might see my syntax error.

I used to need to do that, and someone on this list provided this answer:

The tricky part in the middle is a Perl substitution with regular 
expressions, highlighted below:

rename -v ’s/\.htm$/\.html/’ *.htm

Tip: There is an intro to Perl regular expressions here.

Basically the "s" means substitute. The syntax is s/old/new/ — 
substitute the old with the new.

A . (period) has a special meaning in a regular expression — it means 
"match any character". We don't want to match any character in the 
example above. It should match only a period. The backslash is a way to 
"escape" the regular expression meaning of "any character" and just read 
it as a normal period.


-- 
Regards,

Dick Steffens





More information about the PLUG mailing list