[ale] Generating sequential files with leading zeros from bash

Greg Freemyer greg.freemyer at gmail.com
Fri Apr 6 15:37:46 EDT 2007


All,

I need to do a rename on a bunch of sequential files from something like:

output-000001.pgm
output-000002.pgm
output-000003.pgm
...

to a new name that has a different number of leading zeros and a
different starting number.

I now how to manage the counter, but how can I create a filename with
leading zeros from a bash script and a counter variable.

ie. in C code I would do sprintf(dest_filename, "prefix-%07d.pgm", counter)

Is there something similar to sprintf in bash?

And to make the issue even more difficult, I would like the "07"
portion of the above to itself be variable.  ie. Sometimes I will want
7 digits, other times 8, etc.

Thanks
Greg
-- 
Greg Freemyer
The Norcross Group
Forensics for the 21st Century



More information about the Ale mailing list