Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.shell Subject: Re: Shell wildcard expansion Message-ID: <1991Jun24.195425.26387@convex.com> Date: 24 Jun 91 19:54:25 GMT References: <1991Jun24.144854.8879@ap542.uucp> <13912@mentor.cc.purdue.edu> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 56 Nntp-Posting-Host: pixel.convex.com From the keyboard of ars@cs.brown.edu (Adam Stauffer): : :}I'm looking for a wildcard expansion mechanism, where for example I could :}do mv *.c *.o. :}E.g. an expansion where I only get the * part. : :There is a really nifty program called "mmv" that allows for all sorts :of fun expansions to occur. It is available at uunet.uu.net in vol 21 :of the comp.sources.unix archive... Maybe you didn't look much at rename script that was posted. It allows things like: # strip .bak from files rename 's/\.bak$//' *.bak # call all fortran files nasty rename 's/\.f$/.EVIL/' *.f # make uppercase files be lowercase rename 'tr/A-Z/a-z/' * # make lowercase unless the filename starts with "Make" rename 'tr/A-Z/a-z/ unless /^Make/' * # change all files in entire system of form foo~ into .#foo find / -name '*~' -print | rename 's/(.*)~/.#$1/' # change foo to bar if the user types yes after seeing the name rename 'print "$_: "; s/foo/bar/ if =~ /^y/i' * # make xxx44 into 02C-xxx rename '/^(\D*)(\d+)$/ && $_ = sprintf("%03X-%s", $2, $1)' * The possibilities are literaly limitless. Ok, the last two are admittedly a trifle baroque, but you get the idea. The version posted was a bit elaborate (reads files from stdin, groks -i option, error checking, etc.) The real guts are just: #!/usr/bin/perl $op = shift; for (@ARGV) { $was = $_; eval $op; die $@ if $@; rename($was,$_) unless $was eq $_; } So if you ever misplace it, you can always rewrite it. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."