home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10291 < prev    next >
Encoding:
Text File  |  1992-08-21  |  1.8 KB  |  59 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!psinntp!pool!buck
  3. From: buck@pool.info.sunyit.edu (Jesse Buckley)
  4. Subject: Re: Changing file names
  5. Message-ID: <1992Aug21.191848.20125@pool.info.sunyit.edu>
  6. Organization: State University of New York -- Institute of Technology
  7. References: <ac#n06l.bosak@netcom.com> <13549@chalmers.se>
  8. Date: Fri, 21 Aug 1992 19:18:48 GMT
  9. Lines: 48
  10.  
  11. In article <13549@chalmers.se> biorn@phc.chalmers.se (Bjorn Sandell) writes:
  12. >In article <ac#n06l.bosak@netcom.com>, bosak@netcom.com (Jon Bosak) writes:
  13. >|> 
  14. >|> Here's a problem that must be very common but doesn't seem to get
  15. >|> discussed in books for Unix novices.
  16. >|> 
  17. >|> Suppose I have a directory containing files named, for example,
  18. >|> 
  19. >|>       xyz920815a
  20. >|>       xyz920815b
  21. >|>       xyz920816
  22. >|> 
  23. >|> ...and so on.  I want to change the names of these files to
  24. >|> 
  25. >|>       920815a
  26. >|>       920815b
  27. >|>       920816
  28. >|> 
  29. >|> Who can provide the most elegant solution using just the basic Unix 
  30. >|> tools (cp, mv, sed, awk, sh, csh)?
  31. >
  32. >
  33. >Why not use ksh? 
  34. >
  35. > for file in xyz* ; do
  36. >   mv $file ${file#xyz}
  37. > done
  38.  
  39. Or you could use your fingers...
  40.  
  41. mv xyz920815a 920815a
  42. mv xyz920815b 920815b
  43. mv xyz920816 920816
  44.  
  45. ...
  46.  
  47. I'm kidding.  Use the perl rename script.  If you don't have perl either
  48. get it or whine irrationally until you get it.  I put off getting perl
  49. for the longest time, and now use it for everything.  In fact it is the
  50. one thing that compiled correctly on our HPUX system, without dbm, but
  51. hey HP want's you to buy dbm.  Perl, IMHO, is/should be considered a
  52. basic tool like sed, awk, etc.  And at least, it is the same across
  53. platforms, unlike some of the shells.
  54.  
  55. -- 
  56. =) Buck (buck@sunyit.edu)
  57. "Clothes make the man.  Naked people have little or no influence on
  58. society." -- Mark Twain
  59.