home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!wupost!waikato.ac.nz!aukuni.ac.nz!ecmtwhk
- Newsgroups: comp.unix.questions
- Subject: Re: Changing file names
- Message-ID: <1992Aug20.104721.28955@ccu1.aukuni.ac.nz>
- From: ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig)
- Date: Thu, 20 Aug 1992 10:47:21 GMT
- References: <ac#n06l.bosak@netcom.com> <ceYpFNG00VoxBKON4O@andrew.cmu.edu>
- Organization: University of Auckland, New Zealand.
- Lines: 43
-
- 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
- --
- Thomas Koenig, ecmtwhk@ccu1.aukuni.ac.nz, ib09@rz.uni-karlsruhe.de
- The joy of engineering is to find a straight line on a double logarithmic
- diagram.
-