Re: shell script question
-----BEGIN PGP SIGNED MESSAGE-----
>Sorry, I'm full of questions today.
>I'm working on a script that can rename filenames. For now I want it to add
>an underscore before each capital letter there is in the filename and make
>the capital letter lowercase: e.g. FileName --> _file_name.
>I tried many things like:
>for a in *; do mv $a `echo $a | tr [A] [_a]`;done
>just to try with the letter A. I used quotes in various places, but it
>converts A in _ and not _a. I also tried the -c switch with tr, but that
>messed up thing quite badly.
>So basically my question is 'how to translate one character into two and
>vice versa?' Anyone? Thanks for the input.
rename 's/([A-Z])/_\l$1/g' *
will do the job.
As I already pointed out on this list, rename cames with the standard
perl package of potato.
By the way,
rename 's/([A-Z])/_\l$1/g;s/^_([a-z])/\u$1/' *
will avoid putting the underscore at the beginning, changing back _a
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This email was infected under the terms of the GNU General Public
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.5 and Gnu Privacy Guard <http://www.gnupg.org/>
-----END PGP SIGNATURE-----