python - Fixed file name length of increasing numbers with bash -


i have files names fixed 4 characters in length. like:

0000.png, 0001.png, ... , 0027.png, ..., etc...

they're increasing integers, 0, 1, ..., n. zeros padded additional space number not fill full file name 4 characters.

in python, can loop through these files like:

for in range(n):     file_name = '0'*(4-len(str(n))) + str(n) + '.png' 

how achieve same effect bash? i'm not great bash, '0' padding part throwing me off.

try this:

n=5 ((i=0;i<=$n;i++));    printf -v file_name "%0.4d.png" $i   echo $file_name done 

output:

 0000.png 0001.png 0002.png 0003.png 0004.png 0005.png 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -