tr (tolower) question 
Author Message
 tr (tolower) question

I've been trying to figure out how to do the following:

I'd like to change all the filenames in a directory to lower case.  I
flipped through the awk book and read that I could either use 'tr' to
change the case, or write a function that maps out the letters to do
it.  Well, I wrote the 'tolower' function just fine, but how do I write
a script so that I may ultimately say something like:

system("mv " $1 " " $2);

where $1 is the uppercase name and $2 the lowercase.
Am I going about this wrong?

I've got nawk on my system.

Is there a more elegant way to change case in awk than mapping out the
alphabet?

Thanks in advance,

Jon Azen



Sun, 08 Nov 1998 03:00:00 GMT  
 tr (tolower) question


Quote:

> I'd like to change all the filenames in a directory to lower case.  I
> flipped through the awk book and read that I could either use 'tr' to
> change the case, or write a function that maps out the letters to do
> it.  Well, I wrote the 'tolower' function just fine, but how do I write
> a script so that I may ultimately say something like:

> system("mv " $1 " " $2);

> where $1 is the uppercase name and $2 the lowercase.

If I comprehend correctly, you have already defined a working
function tolower(x), and now you want to do the easy part:

ls | awk '{ system ( "mv " $1 " " tolower($1) ) }' # The answer!

ls | awk '{ print "mv " $1 " " tolower($1) }' | sh # Another answer.

(ignoring details such as already-existing files of the same name, etc).

---------

In this newsgroup, any omission of using "awk" at all may lead to charges
of heresy, but I'll risk mentioning this alternative, which anyone who
hasn't yet written the tolower(x) function may employ:

ls | sed '
h
y/ABC...XYZ/abc...xyz/
G
s/^\(.*\)\n\(.*\)$/mv "\2" "\1"/
' | sh

(replace "sh" with "more" to first check what comes out of "sed" !!!)

Say, how come there isn't a "comp.lang.sed" newsgroup?

-----------------------------------------------------------



Sun, 08 Nov 1998 03:00:00 GMT  
 tr (tolower) question

: a script so that I may ultimately say something like:

: system("mv " $1 " " $2);

: where $1 is the uppercase name and $2 the lowercase.

it is not a good idea to use system() with variables.
rather using system(), write what should be done into
a shell script, which you should check before running.

-grg-



Sun, 08 Nov 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. regexp and tolower

2. toupper / tolower -help

3. SUNOS NAWK - TOLOWER - In a print statement convert string to lower case

4. Awk equivlent of toupper and tolower

5. [string tolower] crashes in certain situations

6. TR: Handheld APL

7. tr, sed, and substitution speed

8. Is there tr for DJGPP ?

9. Emulating "tr"

10. best TR-3 cartridge for backup

11. Need help finding tr.lib code

12. Apple Dylan TR

 

 
Powered by phpBB® Forum Software