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.133235.5248@news.eng.convex.com>
- Date: Thu, 20 Aug 1992 13:32:35 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <ac#n06l.bosak@netcom.com> <ceYpFNG00VoxBKON4O@andrew.cmu.edu> <1992Aug20.104721.28955@ccu1.aukuni.ac.nz>
- 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: 59
-
- From the keyboard of ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig):
- :jf41+@andrew.cmu.edu (Jonathan R. Ferro) writes:
- :
- :>bosak@netcom.com (Jon Bosak) writes:
- :>> [ file name conversion: xyz920815a ==> 920815a ]
- :>>
- :>> Who can provide the most elegant solution using just the basic Unix
- :>> tools (cp, mv, sed, awk, sh, csh)?
- :
- :[perl script deleted]
- :
- :>Unless, of course, you don't consider perl to be a "basic" Unix tool, in
- :>which case you're hopelessly behind the times. :-)
- :
- :On the day when all the systems I use run perl, I'll be happy to use
- :that script, but I lack the disk space and the time to install perl
- :myself. And no, I get to see the new day earlier than most people at the
- :moment :-)
- :
- :Until then, I will use my own home - cooked script, which follows. It
- :will break on file names containing newlines and whitespace, but my
- :filenames don't contain these :-).
- :
- :#! /bin/sh
- :if test $# -eq 0 -o $# -eq 1 -o $# -eq 2
- :then
- : echo "usage: $0 regexp newexp files"
- : exit 1
- :fi
- :re=$1
- :ne=$2
- :shift 2
- :ls $* |
- :nawk \
- :'$0 ~ re { var=$0
- : sub(re,ne,var)
- : print "ls",var " >/dev/null 2>&1 && echo",var,
- : "not clobbered 1>&2 || mv",
- : $0,var
- : } ' re=$re ne=$ne
-
- On the day when all the systems I use run nawk, I'll be happy to use that
- script, but I lack the disk space and the time to install nawk 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, and is in
- fact installed everywhere actually, it's in a globally mounted scripts
- directory, and is a version that does more error checking, understands -i,
- is its own man page, etc.
-
- Actually, I do suppose that I could run the nawk script everywhere by
- running it thru the a2p translator, but since that presupposes perl
- already, why bother?
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
-
- God made the integers; all else is the work of Man.
- -- Kronecker
-