<SUMMARY> Changing CASE

From: William Kuderka (wkuderka@zenith.att.com)
Date: Tue Oct 07 1997 - 14:19:42 CDT


My original question was regarding changing file names with upper case
characters to lower case characters. I was looking for a script becasue I needed
to convert a few hundred files located in various subdirectories. I received
many solid ideas and scripts with which I resolved my problem. My orginal
question is included bellow followed by all the scripts I had been sent at this
moment. I have NOT had a chance to try everyone, but felt they were all worth
sending.

My thanks to all who gave helpfull suggestions.

My question:

> I copied files from an NT box (about 19 MB worth) onto a Solaris
> workstation. All the files are in upper case and I need to
> convert them to lower case.

The suggested solutions:

> > From johnb@Soliton.COM
>
> the tr(1) command can do this:
>
>
> for i in nt*.txt
> do
> tr '[A-Z]' '[a-z]' $i > $i.tr
> done
>
> which will leave all the translated files in file with .tr appended to it
> (well i assumed the files are called nt*.txt, you'll have to specify the
> file names somehow to get this to work). the tr man page has an example
> for dealing with upper to lower case conversion, but accounting for
> locales, etc.

> > From charest@chou.CANR.Hydro.Qc.Ca
>
>
> You can do this with csh or sh or ...
>
> ----- csh -----
> foreach fi (*)
> set new=`echo $fi|tr '[A-Z]' '[a-z]'`
> mv $fi $new
> echo "$fi renamed $new"
> end
> ----- sh -----
> for fi in *; do
> new=`echo $fi|tr '[A-Z]' '[a-z]'`
> mv $fi $new && echo "$fi renammed $new"
> done
> ---------------

> > From neal@ee.pdx.edu
>
> Here's a script that will lower case any file. You can use it like:
>
> find /usr/braindead/NTFILES -exec lcase {} \;
>
> to lowercase every file in a directory tree.
>
> ----Begin lcase----
> #!/bin/csh
> mv $1 `echo $1 | tr \[A-Z\] \[a-z\]`
> ----end lcase----
>

> > From scox@factset.com
>
> This should get you where you want to go...
>
> #!/bin/sh
> for file in *
> do
> NEW=`echo $file | tr "[:upper:]" "[:lower:]"`
> echo "Moving $file to $NEW"
> mv $file $NEW
> done

> > From: Frank Pardo <fpardo@tisny.com>
> Try this:
>
> sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' <old > new
>
>
>

> > From rangern@CIRANO.UMontreal.CA
>
> I have a very old C program to do this.
>
> #include <ctype.h>
> #include <stdio.h>
> #include <string.h>
> main(argc,argv)
> int argc; char *argv[]; {
> int i, j; char l[80],*p;
> for (i=1;i<argc;i++) {
> strcpy(l,argv[i]);
> p=strchr(l,'.');
> if (p==NULL) {continue;}
> j=0;
> for (p=l;*p != '\0';p++)
> if (isupper(*p)) {*p=tolower(*p); j++;}
> if (j != 0) {
> unlink(l);
> rename(argv[i],l);}}}

> > From rali@meitca.com
> for FILE in *
> do
> mv ${FILE} `echo ${FILE} | tr A-Z a-z`
> done

> > From sanjiv@aryabhat.cs.umsl.edu
>
> Easy to write:
>
> for i in *
> do
> tmp=`echo $i | tr "[A-Z]" "[a-z]"`
> mv $i $tmp
> done

> > From marable@firefly.net
>
> Do this:
>
> at filename | tr "[A-Z]" "[a-z]" > newfilename

> > From phil@philco.libs.uga.edu
>
> Here's a script that will do just what you need. Cool!
>
> #!/bin/sh
> # lowerit
> # convert all file names in the current directory to lower case
> # only operates on plain files--does not change the name of directories
> # will ask for verification before overwriting an existing file
> for x in `ls`
> do
> if [ ! -f $x ]; then
> continue
> fi
> lc=`echo $x | tr '[A-Z]' '[a-z]'`
> if [ $lc != $x ]; then
> mv -i $x $lc
> fi
> done
>
> # End of lowerit script

> > From Hill.Michael@tci.com
>
> for i in *; do
> n=`echo $i | tr '[A-Z]' '[a-z]'`
> echo "$i -> $n"
> mv $i $n
> done

> From cld@astro.caltech.edu
>
> Here's a perl script that does it easily.
> If you need to convert the directory names too, change the
> find command to accept directories as well as files.
>
>
> -----------------------------------------------------------
> #!/usr/local/bin/perl
>
> open (FILE, "find . -type file -print |") or die "Couldn't execute command\n";
>
> while (<FILE> ) {
> chomp;
> $newname = $_;
> $newname =~ tr/A-Z/a-z/;
> printf("%s\t%s\n", $_, $newname);
> rename($_, $newname);
> }



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:05 CDT