home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10701 < prev    next >
Encoding:
Internet Message Format  |  1992-09-03  |  2.3 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!dsacg3.dsac.dla.mil!dsac.dla.mil!hq.dla.mil!fazc016
  2. From: fazc016@hq.dla.mil (Don Costello)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: need script to rename uppercase filenames
  5. Message-ID: <866@hq.dla.mil>
  6. Date: 3 Sep 92 17:10:19 GMT
  7. References: <699@svcs1.UUCP>
  8. Organization: HQ Defense Logistics Agency/DASC, Cameron Station, VA
  9. Lines: 50
  10. X-Newsreader: Tin 1.1 PL4
  11.  
  12. slix@svcs1.UUCP (Bill Miller) writes:
  13. : Hi, everyone.
  14. : I'm fairly new to unix, and I need a script or procedure to do the following:
  15. :  
  16. : I have some source code in DOS (many separate files) that I tarred under
  17. : DOS and untarred under 386BSD.  The big problem is that all the files
  18. : came through in UPPERCASE and I need a script to mv (rename) them all
  19. : to lowercase quickly.
  20. :  
  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. :  
  25. :   cat (file) | tr -d '\015' > (newfile)
  26. :  
  27. : It would be nice to combine both of these so that I could rename the
  28. : files to uppercase and strip the extra newlines all in one fell swoop
  29. : instead of doing it one file at a time.
  30.  
  31.   I'm assumming you want to rename the files FROM upper TO lower
  32.   case...
  33.  
  34.   Use "tr" like you did above to change the filename.  The following works
  35.   on BSD4.3:
  36.  
  37.      #!/bin/sh
  38.      #
  39.      for oldfname in *
  40.      do
  41.         cat $oldfname | tr -d '\015' > `echo $oldfname | tr [A-Z] [a-z]`
  42.      done
  43.  
  44.   You still have to remove the "$oldfname" before you end.  I really
  45.   don't think there is a way to do it all at once because you are
  46.   reading the *contents* of the file and sending the lines, less the
  47.   "^M", to a newfile (lowercase of the original).
  48.  
  49.   My suggestion for the future... PKZip the files on your PC, then UnZip
  50.   (using Info-Zip "unzip") and the files will be lower case and the CR/LF 
  51.   translated correctly.
  52.  
  53.   But then again, your question breeds shell practice... :-)).
  54.  
  55.   Cheers  -- dcc --
  56. -- 
  57. +------------------------------------+---------------------------+
  58. | Don Costello, DASC-ZSC             |  It's hard to cram this   |
  59. | DLA Cameron Station, VA            |  signature into just 4    |
  60. | TEL: (703) 274-7215  AV: 284-7215  |  lines!!!                 | 
  61.