Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!apple!amdahl!krs From: krs@uts.amdahl.com (Kris Stephens [Hail Eris!]) Newsgroups: comp.unix.shell Subject: Re: Duelling shells (Re: shell architecture (to glob or not to glob)) Message-ID: <51Z501.344Fu00@amdahl.uts.amdahl.com> Date: 19 Mar 91 19:37:16 GMT References: <488@bria> <00086@meph.UUCP> <1407@sheol.UUCP> <669304840@juliet.cs.duke.edu> <+13AGZ8@xds13.ferranti.com> Reply-To: krs@amdahl.uts.amdahl.com (Kris Stephens [Hail Eris!]) Organization: Amdahl Corporation, Sunnyvale CA Lines: 56 In article <+13AGZ8@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes: >In article <669304840@juliet.cs.duke.edu> drh@duke.cs.duke.edu (D. Richard Hipp) writes: >> In article <1407@sheol.UUCP> throopw@sheol.UUCP (Wayne Throop) writes: >> >...[R]enaming groups of files is a common >> >that *some* tool (whather mv or not) ought to be around to >> >handle it. > >> ls *.x | sed -e 's/\.x//' | while read name; do mv $name.x $name.y; done; > >ls *.x | sed 's/\(.*\).x/mv & \1.y/' | sh This needed to be anchored and to have the real dot escaped: ls *.x | sed 's/\(.*\)\.x$/mv & \1.y/' | sh ^ ^ to avoid errors on, say junk.x11.x which would otherwise create the command mv junk.x junk.y11.x . Note that in both of the cases above, any "hidden" file ending .x won't be found and moved (renamed), and any directory with a name ending '.x' will produce extremely odd results (needs the -d flag added and a filter for directories with names ending .x). --- start ksh version --- : # use in ksh only # # This script moves all *plain* files ending with ".$1" to the ending ".$2". # # The test-filter can be modified so that just directories are filtered # or just directories and pipes or whatever, but for now, if a file isn't # a plain file, we don't rename it. # # Quoting of the arguments inside the loop is important in case there # are shell meta-characters in any of the filenames. # # (Insert all your argument testing stuff here so the following # two lines hold correct info, without the dot) from_suffix=$1 to_suffix=$2 for file in ./*.$from_suffix ./.*.$from_suffix do [ ! -f "$file" ] && continue # skip this other-than-plain file mv "$file" "${file%.$from_suffix}.$to_suffix" done --- end ksh version --- ...Kris -- Kristopher Stephens, | (408-746-6047) | krs@uts.amdahl.com | KC6DFS Amdahl Corporation | | | [The opinions expressed above are mine, solely, and do not ] [necessarily reflect the opinions or policies of Amdahl Corp. ]