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

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!wupost!darwin.sura.net!convex!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: Changing file names
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Aug20.133434.5499@news.eng.convex.com>
  8. Date: Thu, 20 Aug 1992 13:34:34 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <ac#n06l.bosak@netcom.com> <13549@chalmers.se>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 47
  17.  
  18. From the keyboard of biorn@phc.chalmers.se (Bjorn Sandell):
  19. :In article <ac#n06l.bosak@netcom.com>, bosak@netcom.com (Jon Bosak) writes:
  20. :|> 
  21. :|> Here's a problem that must be very common but doesn't seem to get
  22. :|> discussed in books for Unix novices.
  23. :|> 
  24. :|> Suppose I have a directory containing files named, for example,
  25. :|> 
  26. :|>       xyz920815a
  27. :|>       xyz920815b
  28. :|>       xyz920816
  29. :|> 
  30. :|> ...and so on.  I want to change the names of these files to
  31. :|> 
  32. :|>       920815a
  33. :|>       920815b
  34. :|>       920816
  35. :|> 
  36. :|> Who can provide the most elegant solution using just the basic Unix 
  37. :|> tools (cp, mv, sed, awk, sh, csh)?
  38. :
  39. :
  40. :Why not use ksh? 
  41. :
  42. : for file in xyz* ; do
  43. :   mv $file ${file#xyz}
  44. : done
  45.  
  46.  
  47. On the day when all the systems I use run ksh, I'll be happy to use that
  48. script, but I lack the disk space and the time to install ksh myself.
  49. Until then, all systems from any vendor used at Convex run perl by
  50. imperial fiat, so Larry Wall's rename script works quite fine.
  51.  
  52. Note that the ksh solution there works for just that case.  The perl
  53. solution typified by:
  54.  
  55.     rename s/^xyz// *
  56.  
  57. is a general-purpose solution.
  58.  
  59. --tom
  60. -- 
  61.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  62.     If you have ever seen the grim word "login:" on a screen, your mind
  63.     is now a wholly-owned subsidiary of The Death Star.
  64.                 John Woods in <14105@ksr.com> of comp.unix.bsd
  65.