3
1
I've got a bunch of numbered files like this:
file #01.ext
file #02.ext
file #03.ext
file #04.ext
file #05.ext
And what I want is to make them all have three digits (two leading 0's) instead of one, so;
file #001.ext
file #002.ext
file #003.ext
file #004.ext
file #005.ext
My thought is to use sed to replace the # with #0 (which in my case is good enough, there are no files over #99 yet). All the files are in the same folder, how would I do that?
This could've saved me a step earlier. I've been doing it all with sed, and used
ls | grep '[0-9]\{3\}' | sed 's|\(.*\)#0\(.*\)|mv "&" "\1#\2"|' | sh
just to make them have two digits, and then did it the way I listed above. – Rob – 2011-10-30T15:20:09.560I've changed this to the answer, now that I'm learning more about all of this, this is more practical and adaptable. – Rob – 2011-11-08T18:44:34.593
One can use the -v option to printf:
printf -v new "file #%03d.ext" $num
– glenn jackman – 2012-11-01T22:19:09.463