title: bash: sed processing of the files including leading-zeros
body: <p>I am using a bash script to loop over the files pre-defined in several groups of the array within the directory in order to edit the file in case if its exist (for example in the 1st group there are 100 files arranged from 0001 to 0100, in the second group - 50 files arranged from 0001 to 0050 etc).</p>
  
  <pre><code>#an array for the groups
  systems=(one two three four)
  
   # loop over the groups
  for file in "${systems[@]}"; do  
        i="1"
        # introduce K var because the files are numbered as 0001 ... 0100
        k=$(printf '%03d' $i)
        while [  $i -le 100 ]; do
          if [ ! -f "${output}/${file}_${k}.pdb" ]; then
            echo 'File '${output}/${file}_${k}.pdb' does not exits!'
            break
          else
            ## edit file via SED
            # to add i-th number on the first string of the file and substitute smth on the last string;
            sed -i -e '1 i\MODEL '$i'' -e 's/TER/ENDMDL/g' ${output}/${file}_${k}.pdb
            ((i++))
          fi
        done
  done
  </code></pre>
  
  <p>This script doesn't not work on the stage of SED editing, but if I omit usage of the leading zeros in the names of files and use just i-th index within the script, everything works fine:</p>
  
  <pre><code> # loop over the groups
  for file in "${systems[@]}"; do  
        i="1"
        # put k into comment since filles arranged from 1 to 100 without leading zeros; 
        #k=$(printf '%03d' $i)
        while [  $i -le 100 ]; do
          # the filles arranged from 1 to 100
          if [ ! -f "${output}/${file}_${i}.pdb" ]; then
            echo 'File '${output}/${file}_${i}.pdb' does not exits!'
            break
          else
            ## edit file via SED
            # to add i-th number on the first string of the file
            sed -i -e '1 i\MODEL '$i'' -e 's/TER/ENDMDL/g' ${output}/${file}_${i}.pdb
            ((i++))
          fi
        done
  done
  </code></pre>