I am trying to add sequential four digit numbers to the end of file names during a rename script. The problem I am running into is that it only pads the first file and the numbers added are not sequential. Here is my script so far:
Starting file names:
FILE-1.png
FILE-5.png
FILE-14.png
FILE-99.png
FILE-167.png
FILE-199.png
FILE-278.png
FILE-455.png
Script:
a=`printf '%04d' "1"`
cd /${1-$PWD}
for i in *.png;
do mv $i `printf output.%04d.$a.png $(echo $i | sed 's/[^0-9]*//g')`;
let a=a+1
done
EDIT:
I changed the script a bit incorporating the fmt
variable at the top. But I still would like it to name the second set of digits in numerical order of the first set of numbers, as in my Desired output below.
fmt=output.%04d
n=1
cd /${1-$PWD}
for i in *.png;
do mv $i `printf $fmt.%04d.png $(echo $i | sed 's/[^0-9]*//g') "$n"`;
n=$((n+1))
done
My new output:
output.0001.0001.png
output.0005.0007.png
output.0014.0002.png
output.0099.0008.png
output.0167.0003.png
output.0199.0004.png
output.0278.0005.png
output.0455.0006.png
Original output:
output.0001.0001.png
output.0005.7.png
output.0014.2.png
output.0099.8.png
output.0167.3.png
output.0199.4.png
output.0278.5.png
output.0455.6.png
Desired output:
output.0001.0001.png
output.0005.0002.png
output.0014.0003.png
output.0099.0004.png
output.0167.0005.png
output.0199.0006.png
output.0278.0007.png
output.0455.0008.png
As always any help is much appreciated!