Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding zeros to filenames

3 views
Skip to first unread message

sysiphus

unread,
Feb 3, 2012, 7:21:22 AM2/3/12
to
Greetings from a longtime Slacker!

I am trying to get some help that's beyond RTFM. I have an ebook
series in pdf that I am trying to split into its' component books.
When I split the book into pages, it numbers them
1,2,3,...10,11,12...100,101,102...etc., just like it should. I'm
trying to arrange them to merge, but they get listed as
100,101,102.....10,11,12...1......200,201,202....20,21,22,......2, and
so on. I need to add leading zeros to the files (two zeros to single
digit files, one zero to two digit files...) for reassembly.

Any pointers?

sysi...@gmail.com

unread,
Feb 3, 2012, 8:44:06 PM2/3/12
to
Figured it out.

For posterity:

for file in ??[FILENAME].pdf; do mv "$file" "0$file"; done

Crni Gorac

unread,
Feb 4, 2012, 2:04:30 AM2/4/12
to
Or, something like (note "sort -n", this is the most important bit for
handling situations like this):

for file in $(ls -1 *.pdf | sort -n); do
mv $file $(printf "%03d.pdf" ${file%.pdf})
done

Aaron W. Hsu

unread,
Feb 7, 2012, 12:37:32 AM2/7/12
to
In Slackware there is an excellent utility called rename that provides just
this sort of feature for bulk renaming of files based on patterns.

--
Aaron W. Hsu | arc...@sacrideo.us | http://www.sacrideo.us
Programming is just another word for the lost art of thinking.
0 new messages