Shell wildcard expansion
The Grand Master
asg at sage.cc.purdue.edu
Tue Jun 25 03:41:49 AEST 1991
In article <1991Jun24.144854.8879 at ap542.uucp> mike at 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") && open(TTYOUT,">/dev/tty")) {
$inspect++;
select((select(TTYOUT),$|=1)[0]);
}
}
($op = shift) || die "Usage: rename [-i] perlexpr [filenames]\n";
if (!@ARGV) {
@ARGV = <STDIN>;
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 <TTYIN> =~ /^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 at sage.cc.purdue.edu ### ##### #
PUCC ### #
;-) # #
;'> # ##
More information about the Comp.unix.shell
mailing list