I deal with experimental data where filenames are coded using subjects and sessions in the following form:

`sub-01_ses-01_blabla.txt`

I often find myself looping through subjects and sessions by using the following loop:

```
template="sub-01_ses-01_blabla.txt"
for subject in {1..3}; do
    for session in {1..2}; do
    newname=$(echo $template | \
              sed "s/sub-01/sub-$(printf "%02d" $subject)/g" | \
              sed "s/ses-01/ses-$(printf "%02d" $session)/g")
    echo $newname
    done
done

```

Because the following snippet is too verbose and I have to write it over and over in different circumstances, *I'm looking for a more idiomatic and simpler way to **substitute multiple numbers** in the template.* I'm not so experienced with the shell, but any bash builtins or GNU tools may be used.

Could I do that with a simple regex?

Thx.