home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!psinntp!pool!buck
- From: buck@pool.info.sunyit.edu (Jesse Buckley)
- Subject: Re: Changing file names
- Message-ID: <1992Aug21.191848.20125@pool.info.sunyit.edu>
- Organization: State University of New York -- Institute of Technology
- References: <ac#n06l.bosak@netcom.com> <13549@chalmers.se>
- Date: Fri, 21 Aug 1992 19:18:48 GMT
- Lines: 48
-
- In article <13549@chalmers.se> biorn@phc.chalmers.se (Bjorn Sandell) writes:
- >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
-
- Or you could use your fingers...
-
- mv xyz920815a 920815a
- mv xyz920815b 920815b
- mv xyz920816 920816
-
- ...
-
- I'm kidding. Use the perl rename script. If you don't have perl either
- get it or whine irrationally until you get it. I put off getting perl
- for the longest time, and now use it for everything. In fact it is the
- one thing that compiled correctly on our HPUX system, without dbm, but
- hey HP want's you to buy dbm. Perl, IMHO, is/should be considered a
- basic tool like sed, awk, etc. And at least, it is the same across
- platforms, unlike some of the shells.
-
- --
- =) Buck (buck@sunyit.edu)
- "Clothes make the man. Naked people have little or no influence on
- society." -- Mark Twain
-