home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!decwrl!csus.edu!netcom.com!bosak
- From: bosak@netcom.com (Jon Bosak)
- Newsgroups: comp.unix.questions
- Subject: Changing file names
- Message-ID: <ac#n06l.bosak@netcom.com>
- Date: 20 Aug 92 06:18:14 GMT
- Organization: Netcom, a Commercial Internet Service in San Jose
- Lines: 42
-
-
- Here's a problem that must be very common but doesn't seem to get
- discussed in books for Unix novices.
-
- Suppose I have a directory containing files named, for example,
-
- xyz920815a
- xyz920815b
- xyz920816
- xyz920817
- xyz920818a
- xyz920818b
-
- ...and so on. I want to change the names of these files to
-
- 920815a
- 920815b
- 920816
- 920817
- 920818a
- 920818b
-
- ...and so on. Simple, right? Just chop off the first three
- characters and there you are. But how is it done? It's easy if you
- happen to have had the foresight to use dots:
-
- xyz.920815a
- xyz.928815b
- &c.
-
- Then (in csh) you could just use :r and its friends -- but if you had
- that much foresight, you probably wouldn't have gotten into this mess
- in the first place. What's the answer in the general case (including
- instances where the string to be modified appears in the middle of the
- name)? I have a strong intuition that it could be done using awk, but
- without learning that language, I have no idea how. Who can provide
- the most elegant solution using just the basic Unix tools (cp, mv,
- sed, awk, sh, csh)?
-
- +----------------------------------------------------------------------+
- Jon Bosak Sunnyvale, California : bosak@netcom.com jbosak@novell.com
- +----------------------------------------------------------------------+
-