[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Script to rename files

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.

for i in `ls`
  NAME=`basename $i .txt`
  mv $i ${NAME}${NUM}.txt
  NUM=`echo "${NUM} + 1" | bc`

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

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]