home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10694 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.8 KB  |  56 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!nwnexus!Celestial.COM!bill
  3. From: bill@Celestial.COM (Bill Campbell)
  4. Subject: Re: need script to rename uppercase filenames
  5. Organization: Celestial Software, Mercer Island, WA
  6. Date: Thu, 03 Sep 1992 15:12:45 GMT
  7. Message-ID: <1992Sep03.151245.11128@Celestial.COM>
  8. References: <699@svcs1.UUCP>
  9. Keywords: script,tar,msdos
  10. Lines: 44
  11.  
  12. In <699@svcs1.UUCP> slix@svcs1.UUCP (Bill Miller) writes:
  13.  
  14. >Hi, everyone.
  15.  
  16. >I'm fairly new to unix, and I need a script or procedure to do the following:
  17. >I have some source code in DOS (many separate files) that I tarred under
  18. >DOS and untarred under 386BSD.  The big problem is that all the files
  19. >came through in UPPERCASE and I need a script to mv (rename) them all
  20. >to lowercase quickly.
  21. >Since they're in DOS text format, I realize I also need to strip the 
  22. >extra carriage returns on each line.  I've been successful in doing this
  23. >with:
  24. >  cat (file) | tr -d '\015' > (newfile)
  25. >It would be nice to combine both of these so that I could rename the
  26. >files to uppercase and strip the extra newlines all in one fell swoop
  27. >instead of doing it one file at a time.
  28.  
  29. A simple perl solution (needs more error checking):
  30.  
  31. for $dos ( @ARGV ) {
  32.     ( $unix = $dos ) =~ tr/A-Z/a-z/;    # convert to lower case
  33.     if ( -f $unix ) {
  34.         print STDERR "Cannot convert $dos -- $unix exists\n";
  35.         next;
  36.     }
  37.     open(DOS, $dos);
  38.     open(UNIX, "> $unix");
  39.     while (<DOS>) {
  40.         s/\s+$//;   # strip all trailing whitespace including ^M
  41.         print UNIX;
  42.     }
  43.     close(DOS);
  44.     unlink($dos); # remove old dos file
  45.     close(UNIX);
  46. }
  47. -- 
  48. INTERNET:  bill@Celestial.COM   Bill Campbell; Celestial Software
  49. UUCP:   ...!thebes!camco!bill   6641 East Mercer Way
  50.              uunet!camco!bill   Mercer Island, WA 98040; (206) 947-5591
  51. SPEED COSTS MONEY -- HOW FAST DO YOU WANT TO GO?
  52.