Script to rename files
Jeff Vian
jvian10 at charter.net
Fri Jun 3 13:01:39 UTC 2005
On Fri, 2005-06-03 at 10:19 +0200, Juan L. Pastor wrote:
> Hi,
>
> I need a script to rename several files to docXXX.txt where XXX is a
> number I can define, for example 054, and the following files will be
> renamed as 055, 056,... Can you help?
>
> Juan
>
Do you already have the files named?
If so something like this should work.
----------
NUM="054"
for i in `ls`
do
NAME=`basename $i .txt`
mv $i ${NAME}${NUM}.txt
NUM=`echo "${NUM} + 1" | bc`
done
--------
Note that this results in $NUM being the numeric value and it will lose
the leading 0s, so if it is important that it have a fixed number of
digits you will have to test the value of $NUM and pad it with leading
0s appropriately.
> --
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.fsf.org/philosophy/no-word-attachments.html
>
>
>
> ______________________________________________
> Renovamos el Correo Yahoo!
> Nuevos servicios, mas seguridad
> http://correo.yahoo.es
>
More information about the users
mailing list