home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10210 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.7 KB  |  77 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!wupost!darwin.sura.net!convex!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: Changing file names
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Aug20.133235.5248@news.eng.convex.com>
  8. Date: Thu, 20 Aug 1992 13:32:35 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <ac#n06l.bosak@netcom.com> <ceYpFNG00VoxBKON4O@andrew.cmu.edu> <1992Aug20.104721.28955@ccu1.aukuni.ac.nz>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 59
  17.  
  18. From the keyboard of ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig):
  19. :jf41+@andrew.cmu.edu (Jonathan R. Ferro) writes:
  20. :
  21. :>bosak@netcom.com (Jon Bosak) writes:
  22. :>> [ file name conversion: xyz920815a ==> 920815a ]
  23. :>>
  24. :>> Who can provide the most elegant solution using just the basic Unix
  25. :>> tools (cp, mv, sed, awk, sh, csh)?
  26. :
  27. :[perl script deleted]
  28. :
  29. :>Unless, of course, you don't consider perl to be a "basic" Unix tool, in
  30. :>which case you're hopelessly behind the times.  :-)
  31. :
  32. :On the day when all the systems I use run perl, I'll be happy to use
  33. :that script, but I lack the disk space and the time to install perl
  34. :myself. And no, I get to see the new day earlier than most people at the
  35. :moment :-)
  36. :
  37. :Until then, I will use my own home - cooked script, which follows. It
  38. :will break on file names containing newlines and whitespace, but my
  39. :filenames don't contain these :-).
  40. :
  41. :#! /bin/sh
  42. :if test $# -eq 0 -o $# -eq 1 -o $# -eq 2
  43. :then
  44. :    echo "usage: $0 regexp newexp files" 
  45. :    exit 1
  46. :fi
  47. :re=$1
  48. :ne=$2
  49. :shift 2
  50. :ls $* |
  51. :nawk \
  52. :'$0 ~ re { var=$0
  53. :    sub(re,ne,var)
  54. :    print "ls",var " >/dev/null 2>&1 && echo",var,
  55. :    "not clobbered 1>&2 || mv",
  56. :    $0,var
  57. :    } ' re=$re ne=$ne 
  58.  
  59. On the day when all the systems I use run nawk, I'll be happy to use that
  60. script, but I lack the disk space and the time to install nawk myself.
  61. Until then, all systems from any vendor used at Convex run perl by
  62. imperial fiat, so Larry Wall's rename script works quite fine, and is in
  63. fact installed everywhere actually, it's in a globally mounted scripts
  64. directory, and is a version that does more error checking, understands -i,
  65. is its own man page, etc.
  66.  
  67. Actually, I do suppose that I could run the nawk script everywhere by
  68. running it thru the a2p translator, but since that presupposes perl
  69. already, why bother?
  70.  
  71. --tom
  72. -- 
  73.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  74.  
  75. God made the integers; all else is the work of Man.
  76.                 -- Kronecker
  77.