home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!wupost!darwin.sura.net!convex!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: Changing file names
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1992Aug20.133434.5499@news.eng.convex.com>
- Date: Thu, 20 Aug 1992 13:34:34 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <ac#n06l.bosak@netcom.com> <13549@chalmers.se>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 47
-
- From the keyboard of biorn@phc.chalmers.se (Bjorn Sandell):
- :In article <ac#n06l.bosak@netcom.com>, bosak@netcom.com (Jon Bosak) writes:
- :|>
- :|> 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
- :|>
- :|> ...and so on. I want to change the names of these files to
- :|>
- :|> 920815a
- :|> 920815b
- :|> 920816
- :|>
- :|> Who can provide the most elegant solution using just the basic Unix
- :|> tools (cp, mv, sed, awk, sh, csh)?
- :
- :
- :Why not use ksh?
- :
- : for file in xyz* ; do
- : mv $file ${file#xyz}
- : done
-
-
- On the day when all the systems I use run ksh, I'll be happy to use that
- script, but I lack the disk space and the time to install ksh myself.
- Until then, all systems from any vendor used at Convex run perl by
- imperial fiat, so Larry Wall's rename script works quite fine.
-
- Note that the ksh solution there works for just that case. The perl
- solution typified by:
-
- rename s/^xyz// *
-
- is a general-purpose solution.
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
- If you have ever seen the grim word "login:" on a screen, your mind
- is now a wholly-owned subsidiary of The Death Star.
- John Woods in <14105@ksr.com> of comp.unix.bsd
-