Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm trying to write a script to process some images and rename them, or more specifically, renumber them so that pg_0001.png becomes pg_0.png, pg_0002.png becomes pg_1.png, etc. I've looked at the rename command and sed, but I'm not really very familiar with these. It should also be part of a bash script that I've written for the processing of these files - this is what I have so far:
You say that you looked at rename and SED, but you are not familiar with them----Did you look at the man pages or any tutorials? The hardest part of this is actually changing the number
A brute force way using sed--NOT TESTED:
In a folder containing the only files to be renamed:
Code:
for fil in *; do
newnum = $(($(echo $fil|sed 's/[^0-9]//g')-1))
newname = pg_${newnum}.png
mv $fil $newname
done
Test this (or any other code) on some duplicate files in a separate folder.
According to the man page, you can specify the format in which pdftk outputs it's files.
Quote:
burst
Splits a single, input PDF document into individual pages. Also creates a report named doc_data.txt which is the same as the output from dump_data. If the output section is omitted, then PDF pages are named: pg_%04d.pdf, e.g.: pg_0001.pdf, pg_0002.pdf, etc. To name these pages yourself, supply a printf-styled format string via the output section. For example, if you want pages named: page_01.pdf, page_02.pdf, etc., pass output page_%02d.pdf to pdftk.
Edit: By the way, if the above doesn't do it for you, here's a way to rename the files that only uses bash built-ins. No need to call on external tools like sed.
Code:
i=1
for f in pg_*.pdf; do
i=$(printf %02d $i) #zero-pad "$i", if wanted
mv "$f" "${f/%_*.pdf/_$i.pdf}" #replace the orginal file ending with "$i.pdf"
let i++ #increment "$i" for the next file
done
Last edited by David the H.; 01-27-2010 at 08:18 AM.
Reason: additions and formatting
I have scanned a book with Xsane--
the pages have been scanned and stored in sets of 50's in folder named "50odd" "50even"
"100odd" "100even" "150odd" "150even" storing first 50 odd & even, next 50 odd & even, next 50 odd & even pages respectively as image-0001.pnm, image-0002.pnm and so on in each...
Now I wish to
1. know that in future scans can I have Xsane autonumber scan as odd numbers and even numbers seperately as it scans odd numbered pages first and then even numbered pages.
2. do number all files in "50odd" folder as page 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 and in "50even" as 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 and in "100odd" as 27, 29, 31, 33,35, 37, 39, 41, 43, 45, 47, 49 and in "100even" as 26, 28,30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50 and so on..
3. finally add all pages into a pdf book from page 1 to 150 page.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.