-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hans scripsit: >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.
Hi, perl rules:) 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 into A. - -- The Hobbit ICQ #56656060 I am the "ILOVEGNU" signature virus. Just copy me to your signature. This email was infected under the terms of the GNU General Public License. -----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/> iD8DBQE5caCXv9iOG/S6owkRAkssAJ9gRvIqr1X5lSNK2hOlIwQtc/yBrwCdGZIM T4gQXtaxPD6uXS7FsfVWMts= =kO91 -----END PGP SIGNATURE-----