home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!jf41+
- From: jf41+@andrew.cmu.edu (Jonathan R. Ferro)
- Newsgroups: comp.unix.questions
- Subject: Re: Changing file names
- Message-ID: <ceYpFNG00VoxBKON4O@andrew.cmu.edu>
- Date: 20 Aug 92 00:14:17 GMT
- Article-I.D.: andrew.ceYpFNG00VoxBKON4O
- References: <ac#n06l.bosak@netcom.com>
- Organization: Carnegie Mellon, Pittsburgh, PA
- Lines: 37
- In-Reply-To: <ac#n06l.bosak@netcom.com>
-
- 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)?
-
- Put this in your bin directory under the name 'rename':
- ----------
- #!/usr/local/bin/perl
-
- # Usage: rename perlexpr [files]
- # As stolen from the perl distribution.
-
- ($op = shift) || die "Usage: rename perlexpr [filenames]\n";
- if (!@ARGV) {
- @ARGV = <STDIN>;
- chop(@ARGV);
- }
- for (@ARGV) {
- $was = $_;
- eval $op;
- die $@ if $@;
- rename($was,$_) unless $was eq $_;
- }
- ----------
-
- and use the command:
-
- % rename 's/^xyz//' xyz*
-
- Unless, of course, you don't consider perl to be a "basic" Unix tool, in
- which case you're hopelessly behind the times. :-)
-
- --
- Jon Ferro MIT Transportation Modelling Research Center (TMRC)
- jf41+@andrew.cmu.edu "We can hack it!"
- SGNTR VRS VRSN 3.1B: Strppd nd cmprssd fr qckr trnsmssn! nfct yrs tdy!
-