[Techtalk] Looping with numbers in filenames

Michelle Konzack linux4michelle at tamay-dogan.net
Tue Feb 15 23:58:46 UTC 2011


Hello David Sumbler,

Am 2011-02-15 16:49:08, hacktest Du folgendes herunter:
> I have some sets of files which have names such as file1.txt,
> file2.txt ... file25.txt.
> 
> I want to perform an operation on all the files:in other words, I need
> to be able to do something like
> 
> for integer = str(1 to 25)
>      do something to file$integer.txt
> next
> 
> How can I do this at the bash input?

    for NUM in $(seq 1 25)
    do
      file${NUM}.txt
    done

and if the Files have an equal width, use

    for NUM in $(seq --equal-width 1 25)
    do
      file${NUM}.txt
    done

which prefix the 1-9 with a 0.

Thanks, Greetings and nice Day/Evening
    Michelle Konzack

-- 
##################### Debian GNU/Linux Consultant ######################
   Development of Intranet and Embedded Systems with Debian GNU/Linux

itsystems at tdnet France EURL       itsystems at tdnet UG (limited liability)
Owner Michelle Konzack            Owner Michelle Konzack

Apt. 917 (homeoffice)
50, rue de Soultz                 Kinzigstraße 17
67100 Strasbourg/France           77694 Kehl/Germany
Tel: +33-6-61925193 mobil         Tel: +49-177-9351947 mobil
Tel: +33-9-52705884 fix

<http://www.itsystems.tamay-dogan.net/>  <http://www.flexray4linux.org/>
<http://www.debian.tamay-dogan.net/>         <http://www.can4linux.org/>

Jabber linux4michelle at jabber.ccc.de
ICQ    #328449886

Linux-User #280138 with the Linux Counter, http://counter.li.org/


More information about the Techtalk mailing list