Correcting file numbers using bash
<p>I have a bunch of file names in a folder like this:</p>

<pre><code>test_07_ds.csv
test_08_ds.csv
test_09_ds.csv
test_10_ds.csv
...
</code></pre>

<p>I want to decrease the number of every file, so that these become: </p>

<pre><code>test_01_ds.csv
test_02_ds.csv
test_03_ds.csv
test_04_ds.csv
...
</code></pre>

<p>Here's what I came up with:</p>

<pre><code>for i in $1/*; do
    n=${i//[^0-9]/};
    n2=`expr $n - 6`;
    if [ $n2 -lt 10 ]; then
        n2="0"$n2;
    fi
    n3=`echo $i | sed -r "s/[0-9]+/$n2/"`
    echo $n3;
    cp $i "fix/$n3";
done;
</code></pre>

<p>Is there a cleaner way of doing this?</p>