Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Might check your local 'tr' manual. Usually the GNU version at least has a
[:upper:] and [:lower:] that you can use and is more likely to catch
anything you might miss. Probably doesn't matter but it could in the
future.. if you might be using the script for a while.
Otherwise looks pretty much like I'd do it. Might check to make sure the
file doesn't already exist before writing it.
"...If you want to build a ship, don't drum up people together to collect
wood and don't assign them tasks and work, but rather teach them to long
for the endless immensity of the sea." -- Antoine de Saint-Exupery
;):):-):):-):):-)8')
Michael McGlothlin <EMAIL:PROTECTED>
http://kavlon.org/projects/
On Wed, 2 Oct 2002, Mike Miller wrote:
> On Wed, 2 Oct 2002, Michael wrote:
>
> > The 'tr' command can be used to change a filename to lowercase, remove
> > spaces, etc.
>
> You mean like this:
>
> # echo "FILENAME" | tr '[A-Z]' '[a-z]'
> filename
>
> That's the way I was going to approach this, in a tcsh script like this
> one:
>
> ----------begin script on next line------------
> #!/usr/local/bin/tcsh -f
>
> # lcf - translate filenames to lowercase and renames files
> # Syntax:
> # lcf filename
> # Wildcards are allowed but * and ? should be escaped, that is,
> # entered as \* and \?. If a path is entered, as in
> # lcf dir/subdir/filename
> # then all dirs and subdirs must already be lowercase.
>
> foreach file ("`\ls -1 $*`")
> set oldname="$file"
> set newname=`echo $file | tr '[A-Z]' '[a-z]'`
> mv "$oldname" "$newname"
> end
> ----------end script on previous line----------
>
>
> The benefit of that script is that you simply give it the filenames just
> as you would give them to ls. For example, if I were to name the script
> lcf for "lowercase filenames", I could run this command:
>
> lcf [LSW]* NO* ABCNEWS.txt APNI? www/junk/[A-Z]*
>
> and it would find and rename all of the indicated files appropriately.
> This is because the "$*" on the first line reads in all of the command
> line arguments and sends them to ls ("\ls" to override aliases and "-1" to
> make a single column), but there is one quirk to this: it is safer to use
> \* and \? instead of * and ?. For example: lcf * doesn't work but
> lcf \* does work. The script seems to handle filenames with spaces just
> fine. It will not recurse, but it will work on files in subdirectories so
> long as the subdirectories already have lowercase filenames.
>
> Is this any better or worse than the other solutions? (perl and bash?)
>
> Mike
>
> --
> To unsubscribe, go to http://mlug.missouri.edu/members/edit.php
>
> Archives are available at http://mlug.missouri.edu/list-archives/
>
--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php
Archives are available at http://mlug.missouri.edu/list-archives/