moving upper case names to lower case

Guy Harris guy at auspex.auspex.com
Thu Aug 24 04:26:29 AEST 1989


>It's easier to write and compile this than to get tr to massage
>the string for you.  

Well, maybe, but I really tend to doubt it.  The algorithm for finding
the right "tr" command is:

	if (you have S3 or S5 (or V6?))
		use the command

			tr '[A-Z]' '[a-z]'

	else /* you have V7 or 2.xBSD or 4.xBSD */
		use the command

			tr 'A-Z' 'a-z'

which strikes *me* as being easier than typing in and compiling said
program (fewer characters, for one thing!).

And there's even an optimization; given the way the V7/2.xBSD/4.xBSD
"tr" parses its arguments, the command

	tr '[A-Z]' '[a-z]'

will do the right thing (it will translate '[' to '[' and ']' to ']', as
well as translating upper-case letters to lower-case letters; this trick
does *not* work in general, though, since '[' and ']' don't have special
meaning to the V7/2.xBSD/4.xBSD "tr").

In either case, of course, you have to feed the file names to this
program, extract the file names out the other end, and use them in an
"mv" command, which strikes me as more work than just getting the
translation done.  Once you've gotten the list of file names, I would be
tempted to try:

	for i in <the list>	# note - <the list> is not to be typed
				# literally; it's the list of file names
	do
		mv $i `echo $i | <the command>`
	done

where <the command> is the "tr" command in question (or, if you're
really insistent, the case-translation program supplied).  (Said "for"
construct is, of course, a Bourne shell construct, so if your login
shell is the C shell you'd either have to 1) use the C shell equivalent
or 2) type "sh" before typing in the construct; the C shell equivalent
is left as an exercise for the reader.)



More information about the Comp.unix.questions mailing list