need script to change case

need script to change case

Post by rogerd.. » Tue, 02 May 2000 04:00:00



I have several hundred files in a directory
that I'd like to be all lower case.

Anything in your bag o' tricks?

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

need script to change case

Post by gregg_har.. » Tue, 02 May 2000 04:00:00




> I have several hundred files in a directory
> that I'd like to be all lower case.

> Anything in your bag o' tricks?

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Give this a try:

#!/bin/ksh

names="urmpr01 urmpr02 "
for i in $names
do
        cat /dnsdir/config/hosts.pbco | tr "[:upper:]" "[:lower:]" |
        awk -v name=$i ' { if ( $2 ~ name) {
                chr = substr($1,1,1);
                if ( chr != "#" ) {
                        #print $0;
                        #print "changed to"
                        print "#" $0;
                        #print name;
                        }
                }
        }'
done #> /tmp/hosts.pbco

#diff /tmp/hosts.pbco /dnsdir/config/hosts.pbco

Of course change the names to what you need.

Gregg

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

need script to change case

Post by Barry Margoli » Tue, 02 May 2000 04:00:00



>I have several hundred files in a directory
>that I'd like to be all lower case.

>Anything in your bag o' tricks?

It's in the FAQ!

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

need script to change case

Post by Erik Max Franci » Tue, 02 May 2000 04:00:00



> I have several hundred files in a directory
> that I'd like to be all lower case.

> Anything in your bag o' tricks?

In zsh:

    for i in *[A-Z]*; mv $i $i:l

--

  Alcyone Systems | web http://www.alcyone.com/max/ | 971.363 Ms p.L.
 San Jose, CA, US | icbm 37 20 N 121 53 W | 245 days left | &tSftDotIotE
__________________| Crank Dot Net -- http://www.crank.net/
 __
/  \ Of war men ask the outcome, not the cause.
\__/ Seneca

 
 
 

need script to change case

Post by Christoph Lang » Tue, 02 May 2000 04:00:00



> I have several hundred files in a directory
> that I'd like to be all lower case.
> Anything in your bag o' tricks?

for file
do
  mv "$file" "`echo $file | tr '[:upper:]' '[:lower:]'`"
done

[:upper:] and [:lower:] are better than [A-Z] and [a-z] because they
handle international character sets correctly.

HTH

Christoph

--
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
Christoph Lange

 
 
 

need script to change case

Post by Friedrich Dominicu » Wed, 03 May 2000 04:00:00



> I have several hundred files in a directory
> that I'd like to be all lower case.

> Anything in your bag o' tricks?

with SCSH

(for-each (lambda (file) (rename-file file (downcase-string file)))
        (glob "*"))

works even for filenames with blanks in them if you know the directory
you can do it this way

(define (to-downcase-in dir)
        (with-cwd dir
        (for-each .... (directory-files ))))

if you like you can abstract it away with s.th like

(define (rename dir proc-on-file)
  (with-cwd dir
                        (for-each (lambda (file) (rename-file file (proc-on-file file)))
                                          (directory-files))))

You can use for proc anything you like downcase-string upcase-string or any other function takes a string and returns another one. Quite nice, isn'it ;-)

Regards
Friedrich

 
 
 

need script to change case

Post by Juli » Fri, 05 May 2000 04:00:00


Got this from UGU's tips and tricks the other day.  Haven't tried it
yet, but sounds like it might be of some use to you.

RENAME FILES UPPERCASE TO LOWERCASe

To change all the files requested from
uppercase to lowercase simply use the following
script:

 ------------------------------- CUT HERE --------------

#!/bin/sh

#
# up2lo - rename files from uppercase to lower case.
#
for i in $*
do
   file=`echo $i | tr "[A-Z]" "[a-z]"`
   mv $i $file
done

 ------------------------------- CUT HERE --------------

To rename all the files from uppercase to lowercase inside
a directory you only have to use the following command:

% up2lo *

Good luck.


> I have several hundred files in a directory
> that I'd like to be all lower case.

> Anything in your bag o' tricks?

> Sent via Deja.com http://www.deja.com/
> Before you buy.