Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!masscomp!ocpt!princeton!phoenix!pfalstad From: pfalstad@phoenix.princeton.edu (Paul Falstad) Newsgroups: comp.unix.shell Subject: Re: Shell wildcard expansion Message-ID: <85621@notavax.Princeton.EDU> Date: 25 Jun 91 07:34:15 GMT References: <13912@mentor.cc.purdue.edu> <1991Jun24.195425.26387@convex.com> Sender: gnus@idunno.Princeton.EDU Organization: League For Fighting Chartered Accountancy Lines: 59 Warning! zsh plug ahead. Sensitive readers hit 'n'. $ /usr/local/bin/zsh % rename () { eval 'shift; for i; mv $i $i:'$1 } tchrist@convex.COM (Tom Christiansen) wrote: ># strip .bak from files > rename 's/\.bak$//' *.bak % rename s/.bak// *.bak ># call all fortran files nasty > rename 's/\.f$/.EVIL/' *.f % rename s/.f/.EVIL/ *.f ># make uppercase files be lowercase > rename 'tr/A-Z/a-z/' * % rename l * ># make lowercase unless the filename starts with "Make" > rename 'tr/A-Z/a-z/ unless /^Make/' * % set -o extendedglob % rename l ^Make* ># change all files in entire system of form foo~ into .#foo > find / -name '*~' -print | rename 's/(.*)~/.#$1/' Afraid my rename can't tackle this one. Try this though: % for i in /..../*~; mv $i ".#${i%~}" ># change foo to bar if the user types yes after seeing the name > rename 'print "$_: "; s/foo/bar/ if =~ /^y/i' * % for i in *; if read "j?$i: "; [[ $j = y* ]]; then mv $i $i:s/foo/bar/; fi ># make xxx44 into 02C-xxx > rename '/^(\D*)(\d+)$/ && $_ = sprintf("%03X-%s", $2, $1)' * Oh well. >So if you ever misplace it, you can always rewrite it. Since my rename function is so simple, I don't bother to define it; I usually just type out the zsh commands to do what I want: % for i in *.bak; mv $i $i:s/.bak// However, if you have a filename like "foo.bak.bar.bak", then $i:s/.bak// will give "foo.bar.bak" instead of the desired "foo.bak.bar"; ${i%.bak} does what you want. -- Paul Falstad | 10 PRINT "PRINCETON CS" pfalstad@phoenix.princeton.edu | 20 GOTO 10