[Techtalk] Looping with numbers in filenames

Kathryn Hogg kjh at flyballdogs.com
Tue Feb 15 16:59:29 UTC 2011


David Sumbler wrote:
> 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?

num=1
while expr $num '<' 26 >/dev/null
do
  echo $file${num}.txt
  num=$(expr $num + 1)
done

-- 
Kathryn
http://womensfooty.com
US Freedom Signup: http://womensfooty.com/freedom/2011


More information about the Techtalk mailing list