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

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!pipex!warwick!cudcv
  3. From: cudcv@warwick.ac.uk (Rob McMahon)
  4. Subject: Re: Changing file names
  5. Message-ID: <wfgpbc1j@csv.warwick.ac.uk>
  6. Sender: news@csv.warwick.ac.uk (Network news)
  7. Nntp-Posting-Host: shark
  8. Organization: Computing Services, Warwick University, UK
  9. References: <ac#n06l.bosak@netcom.com> <31810002@hpcuhe.cup.hp.com> <1992Aug21.135128.20589@news.eng.convex.com>
  10. Date: Sat, 22 Aug 1992 15:11:38 GMT
  11. Lines: 40
  12.  
  13. In article <1992Aug21.135128.20589@news.eng.convex.com> tchrist@convex.COM
  14. (Tom Christiansen) writes: 
  15. >:for i in `ls`
  16. >:do
  17. >:  echo $i | sed s/xyz// >j
  18. >:  mv $i `cat j`
  19. >:done
  20. >:rm j
  21. >
  22. >Process pig.  Why not
  23. >
  24. >    mv $i `echo $i | sed 's/^xyz//'`
  25. >
  26. >Also, your method is going to earn you a lot of
  27. >
  28. >    mv: foo and foo are identical
  29. >
  30. >errors.
  31.  
  32. Minor critism :-)  you failed to criticise the "for in in `ls`" when he could
  33. have done "for i in *", or in this case "for i in xyz*".
  34.  
  35. I think we've come down to
  36.  
  37. for i in xyz*
  38. do
  39.   mv "$i" "`echo \"$i\" sed 's/^xyz//'`"
  40. done
  41.  
  42. Oops.  I seem to have slipped another critism in (not enough quotes).  I hate
  43. scripts that can't deal with arbitrary filenames.  This is one of the good
  44. points of {,t}csh, with its $var:q.
  45.  
  46. Cheers,
  47.  
  48. Rob
  49. -- 
  50. UUCP:   ...!mcsun!uknet!warwick!cudcv    PHONE:  +44 203 523037
  51. JANET:  cudcv@uk.ac.warwick             INET:   cudcv@warwick.ac.uk
  52. Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England
  53.