Help with bash command to change lots of file names

greadey anything at greadey.uklinux.net
Thu May 9 23:25:42 BST 2002


    Hi peeps,

I have a directory with lots of files called CHAPN.TXT where n is a
number from 1 to 14.  I want to turn them all into latex files and so
for ease of editing in Vim I want to change them all to chN.tex.  I have
been trying to write a bash command to do it with a for loop and sed and
I basically have;

for f in *
do
NEW=`echo $f | sed -e 's/CHAP \( \W+ \. \) /ch \1 tex/ ' ` # I've put
whitespace in for clarity
#mv $f $NEW
echo $NEW
done

I have tried different quotes and I believe my regexp is correct but
when I run this command or any variation I either get an error if I use
all single quotes instead of backticks and single quotes or the command
just prints all the original file names.

Can someone tell me where I am going wrong?

Thanks in advance

greadey.





More information about the Ukfreebsd mailing list