[plug] Does anyone know how to change bulk filenames...

Matt Kemner zombie at networx.net.au
Mon Jul 13 11:21:34 WST 1998


On Mon, 13 Jul 1998, Bevan Broun wrote:

> > for FILE in *.txt
> > do
> > mv $FILE `echo $FILE|sed 's,\.txt$,\.doc'`
> > done
> Matt should have added that this is only for bourne
> shell compatable shells. Wont work for tcsh, csh.

You're right, I should have.. To make up for it I'll tell you how to do it
in tcsh too :)

foreach FILE ( *.txt)
mv $FILE `echo $FILE|sed 's,\.txt$,\.doc'`
end

and if you're using the zsh, you will be happy to know it will accept both
ways of doing it, as well as several others.
 
> It gets really nice when you replace "in *.txt" with "in `SOME GOOD
> COMMANDS | AND PIPES`

Tell me about it :) there are so many things that are made easier by a few
simple (ok, complex :P) shell scripts (for example clearing a mailspool of
yet another mailbomb) that it's a must for every sysadmin-wannabe

 - Matt

P.S. thanks to Chris McDonald for introducing me to sed (much as I hated
it at first) and good shell scripting, and running an excellent Unix
course in '96



More information about the plug mailing list