Using bash:
for file in t10*/data/file.dat*
do
if [[ $file =~ (t10n([[:digit:]]+)/data/file.dat)([[:digit:]]+) ]]
then
echo mv -- "$file" "${BASH_REMATCH[1]}$(( ${BASH_REMATCH[2]} * 5 + ${BASH_REMATCH[3]} ))"
fi
done
The heavy lifting is done by the =~
regular-expression operator in the [[
test operation. There are three parenthesized expressions in order to grab the elements we're interested in:
- the bulk of the filename, except for the trailing
dat
number
- the
t10n
number
- the
dat
number
If the file matches the pattern, then the resulting values are in the BASH_REMATCH array, so we use those to calculate the new filename.
Remove the echo
if the results look correct.
Sample input:
mkdir -p t10n2/data t10n3/data
touch t10n2/data/{file.dat0,file.dat1,file.dat2}
touch t10n3/data/{file.dat0,file.dat1,file.dat2}
Sample output:
mv -- t10n2/data/file.dat0 t10n2/data/file.dat10
mv -- t10n2/data/file.dat1 t10n2/data/file.dat11
mv -- t10n2/data/file.dat2 t10n2/data/file.dat12
mv -- t10n3/data/file.dat0 t10n3/data/file.dat15
mv -- t10n3/data/file.dat1 t10n3/data/file.dat16
mv -- t10n3/data/file.dat2 t10n3/data/file.dat17
find
,mv
etc.