Haatschii Haatschii - 2 months ago 11
Bash Question

Shell script loop over filenames from 0000 to 1500

I'm trying to create a shell script that shall convert certain Files according to some rules. The files are organized like this:

file_0000.adat
file_0001.adat
file_0002.adat
file_0003.adat
...
file_0010.adat
file_0011.adat
...
file_9999.adat


My current script looks like this:

#!/bin/sh

lauf=$(expr 0)

for filename in ../distData/file_*.adat
do
...
lauf=$(expr $lauf + 1)
done;


But now I only want the files with numbers from 0000 to 1500. For the conversion I need the number of the file (done by the variable
lauf
in the script). Can't figure out how to do this right now.

Thanks for replys.

Mat Mat
Answer

Try something like:

for i in $(seq -w 1500) ; do
  if [ -f ../distData/file_${i}.adat ] ; then
    # do whatever, the file number is ${i}
  fi
done
Comments