home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10200 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  1.6 KB

  1. Path: sparky!uunet!olivea!decwrl!csus.edu!netcom.com!bosak
  2. From: bosak@netcom.com (Jon Bosak)
  3. Newsgroups: comp.unix.questions
  4. Subject: Changing file names
  5. Message-ID: <ac#n06l.bosak@netcom.com>
  6. Date: 20 Aug 92 06:18:14 GMT
  7. Organization: Netcom, a Commercial Internet Service in San Jose
  8. Lines: 42
  9.  
  10.  
  11. Here's a problem that must be very common but doesn't seem to get
  12. discussed in books for Unix novices.
  13.  
  14. Suppose I have a directory containing files named, for example,
  15.  
  16.       xyz920815a
  17.       xyz920815b
  18.       xyz920816
  19.       xyz920817
  20.       xyz920818a
  21.       xyz920818b
  22.  
  23. ...and so on.  I want to change the names of these files to
  24.  
  25.       920815a
  26.       920815b
  27.       920816
  28.       920817
  29.       920818a
  30.       920818b
  31.  
  32. ...and so on.  Simple, right?  Just chop off the first three
  33. characters and there you are.  But how is it done?  It's easy if you
  34. happen to have had the foresight to use dots:
  35.  
  36.       xyz.920815a
  37.       xyz.928815b
  38.       &c.
  39.  
  40. Then (in csh) you could just use :r and its friends -- but if you had
  41. that much foresight, you probably wouldn't have gotten into this mess
  42. in the first place.  What's the answer in the general case (including
  43. instances where the string to be modified appears in the middle of the
  44. name)?  I have a strong intuition that it could be done using awk, but
  45. without learning that language, I have no idea how.  Who can provide
  46. the most elegant solution using just the basic Unix tools (cp, mv,
  47. sed, awk, sh, csh)?
  48.  
  49. +----------------------------------------------------------------------+
  50.  Jon Bosak  Sunnyvale, California : bosak@netcom.com  jbosak@novell.com
  51. +----------------------------------------------------------------------+
  52.