[Gllug] Changing case on filenames

Tom Gilbert tom at linuxbrit.co.uk
Tue Mar 5 00:38:09 UTC 2002


* Rob Andrews (rob at impure.org.uk) wrote:
> [04-Mar-2002 21:36.23 (GMT) / Gordon Joly]
>  > >This wonderful technique can be built on:-
>  > >for i in *; do
>  > >mv $i `echo $i | tr 'A-Z' 'n-za-m'`
>  > >done
>  > which shell?
> 
> My suspicion tells me that won't work, since $ will be quoted directly due
> to the single quotes.

Those aren't single quotes, those are backticks, which act as double
quotes when it comes to variable substitution.

> Additionally, the internal single quotes are unescaped, so they'll break.

No they won't :)

> But back to the original question, it should work with any bourne compatible
> shell.

What you all want is rename.pl, originally written by Larry Wall:
http://linuxbrit.co.uk/downloads/rename.pl

$ rename.pl 's/foo/bar/' *
$ rename.pl 'tr/A-Z/a-z/' *
$ rename.pl '$_=ucfirst lc' *
$ rename.pl 's/^foo (\d+).mp3$/blah $1 foo.mp3/' *.mp3

Any perl expression you like, which operates on $_.

(This is a version I tweaked to create a .undo file in the current
directory, for those, oops, I broke the regexp moments: ". .undo").

Tom.
-- 
   .^.    .-------------------------------------------------------.
   /V\    | Tom Gilbert, London, England | http://linuxbrit.co.uk |
 /(   )\  | Open Source/UNIX consultant  | tom at linuxbrit.co.uk    |
  ^^-^^   `-------------------------------------------------------'

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list