home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10203 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  1.4 KB

  1. Path: sparky!uunet!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!jf41+
  2. From: jf41+@andrew.cmu.edu (Jonathan R. Ferro)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Changing file names
  5. Message-ID: <ceYpFNG00VoxBKON4O@andrew.cmu.edu>
  6. Date: 20 Aug 92 00:14:17 GMT
  7. Article-I.D.: andrew.ceYpFNG00VoxBKON4O
  8. References: <ac#n06l.bosak@netcom.com>
  9. Organization: Carnegie Mellon, Pittsburgh, PA
  10. Lines: 37
  11. In-Reply-To: <ac#n06l.bosak@netcom.com>
  12.  
  13. bosak@netcom.com (Jon Bosak) writes:
  14. > [ file name conversion: xyz920815a ==> 920815a ]
  15. >
  16. > Who can provide the most elegant solution using just the basic Unix
  17. > tools (cp, mv, sed, awk, sh, csh)?
  18.  
  19. Put this in your bin directory under the name 'rename':
  20. ----------
  21. #!/usr/local/bin/perl
  22.  
  23. # Usage: rename perlexpr [files]
  24. # As stolen from the perl distribution.
  25.  
  26. ($op = shift) || die "Usage: rename perlexpr [filenames]\n";
  27. if (!@ARGV) {
  28.     @ARGV = <STDIN>;
  29.     chop(@ARGV);
  30. }
  31. for (@ARGV) {
  32.     $was = $_;
  33.     eval $op;
  34.     die $@ if $@;
  35.     rename($was,$_) unless $was eq $_;
  36. }
  37. ----------
  38.  
  39. and use the command:
  40.  
  41. % rename 's/^xyz//' xyz*
  42.  
  43. Unless, of course, you don't consider perl to be a "basic" Unix tool, in
  44. which case you're hopelessly behind the times.  :-)
  45.  
  46. --
  47. Jon Ferro        MIT Transportation Modelling Research Center (TMRC)
  48. jf41+@andrew.cmu.edu    "We can hack it!"
  49. SGNTR VRS VRSN 3.1B: Strppd nd cmprssd fr qckr trnsmssn! nfct yrs tdy!
  50.