Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sample.eng.ohio-state.edu!purdue!mentor.cc.purdue.edu!sage.cc.purdue.edu!asg From: asg@sage.cc.purdue.edu (The Grand Master) Newsgroups: comp.unix.shell Subject: Re: Shell wildcard expansion Message-ID: <13912@mentor.cc.purdue.edu> Date: 24 Jun 91 17:41:49 GMT References: <1991Jun24.144854.8879@ap542.uucp> Sender: news@mentor.cc.purdue.edu Reply-To: asg@sage.cc.purdue.edu (The Grand Master) Organization: Purdue University Lines: 93 In article <1991Jun24.144854.8879@ap542.uucp> mike@ap542.uucp (Mike Hoffmann) writes: } }Hi! } }I have no idea if this is a FAQ, but anyway. } }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. Are you saying that you want $ ls hi.c there.c how.c areyou.c $ mv *.c *.o $ ls hi.o there.o how.o areyou.o If so then here is a program called rename that is written in perl. The syntax is: rename s/\.c/\.o/ *.c i.e. rename (some sort of regexp replacement a la ed) (list of files on which to perform this replacement) Here it is ---------------cut here-------------- #! /usr/unsup/bin/perl 'di'; 'ig00'; # # $Header: /userb/asg/bin/RCS/rename,v 1.0 91/03/20 10:51:47 asg Exp Locker: asg $ # # $Log: rename,v $ # Revision 1.0 91/03/20 10:51:47 asg # Initial revision # # Revision 3.0.1.2 90/08/09 03:17:57 lwall # patch19: added man page for relink and rename # if ($ARGV[0] eq '-i') { shift; if (open(TTYIN, "/dev/tty")) { $inspect++; select((select(TTYOUT),$|=1)[0]); } } ($op = shift) || die "Usage: rename [-i] perlexpr [filenames]\n"; if (!@ARGV) { @ARGV = ; chop(@ARGV); } for (@ARGV) { unless (-e) { print STDERR "$0: $_: $!\n"; $status = 1; next; } $was = $_; eval $op; die $@ if $@; if ($was ne $_) { if ($inspect && -e) { print TTYOUT "remove $_? "; next unless =~ /^y/i; } unless (rename($was, $_)) { print STDERR "$0: can't rename $was to $_: $!\n"; $status = 1; } } } exit $status; ------------cut here------------- Hope this helps Bruce --------- ### ## Courtesy of Bruce Varney ### # aka -> The Grand Master # asg@sage.cc.purdue.edu ### ##### # PUCC ### # ;-) # # ;'> # ##