The Linux Chronicles #4: Overcoming the Problem of Trying to Scan Thousands of Two-Sided Pages with a Non-Duplexing Scanner.

Weapon of Choice: 1957 Tower Commander And this is after I already chewed through two volumes…

I’m not real sure where I’ll store these Victor manuals after they’re scanned. The shelves are gettin’ pretty full of reference material.

Wildlife Photography indoors. Everything’s indoors…

The Process:

First I scanned the whole book on one side, saving the first-side files into a folder called “0001”. Then I scanned the second-side files into a folder called “0002”. Of course, when you scan the second side, the pages will be numbered in reverse order because you’re starting at the back of the book and scanning forward. We’ll deal with this when we script the program to merge the two directories together. The basic process we want will be:

1) read the contents of folder “0001” into an array.
2) read the contents of folder “0002” into an array, and then reverse the array order.
3) Iterate through array 1, copying each file to a folder called “final”, and re-numbering them in +2 increments starting at #0.
4) Iterate through array 2, doing the same thing, but starting at #1.

And that’s it. The result should be a “final” folder containing the files ordered so that page 1 is page 1 from folder 001, page 2 is page 1 from folder 002, page 3 is page 2 from folder 001, page 4 is page 2 from folder 002, and so on. This replicates the result of having scanned the book with a duplexing ADF. Here’s my BASH script, in case you need to do such a thing yourself with a similarly limited scanner. (:

#!/bin/bash

# Function for reversing an array
reverse(){
local arrayname=${1:?Array name required} array revarray e
eval “array=( \”\${$arrayname[@]}\” )”
for e in “${array[@]}”
do
revarray=( “$e” “${revarray[@]}” )
done
eval “$arrayname=( \”\${revarray[@]}\” )”
}

# Declare our working arrays
declare -a folder1
declare -a folder2

# read files in folder1 into array
for file in 0001/*.jpg
do
folder1=(${folder1[*]} “$file”)
done

#read files in folder2 into array
for file in 0002/*.jpg
do
folder2=(${folder2[*]} “$file”)
done

# Process Folder 1, rename files incrementing +2, starting at 0
i=0
echo -e ‘\nProcessing Folder 1 ———————————–‘
for item in “${folder1[@]}”
do
printf -v num ‘%04d’ $i
echo “IMG: $item >> final/IMG_$num.jpg”
cp $item final/IMG_$num.jpg
i=$((i+2))
done

# Process Folder 2, reverse array and rename files incrementing +2, starting at 1
reverse folder2
i=1
echo -e ‘\nProcessing Folder 2 ———————————–‘
for item in “${folder2[@]}”
do
printf -v num ‘%04d’ $i
echo “IMG: $item >> final/IMG_$num.jpg”
cp $item final/IMG_$num.jpg
i=$((i+2))
done

Very pleased to have friends who are handy with a sewing machine…

Some sort of Magical Moon tonight. Resident witch is powering up her crystals with Lunar Juice.

Updated: April 7, 2020 — 11:59 pm

6 Comments

Add a Comment
  1. Cleverness!

    I follow the office machine collecting scene in Germany, where there is equal interest in calculators and typewriters. The calculator people tend to be, as you’d expect, mathematically and mechanically gifted. Some of them publish intricate analyses of how these complicated machines work. So I think that, sooner or later, someone is going to be grateful for your work publishing these rare technical manuals.

    1. I hope so – these manuals are fascinating for the completely different way that what I think of as computing functions are rendered as mechanical designs. The books generally are organized as Parts & Service, then hundreds of pages of Function Testing exercises showing how to execute the logic testing to ensure that the mechanics are functioning properly. Crazy stuff that I can barely penetrate myself. (:

  2. You’re doing The Right Thing, Ted. Calculators have much of the same appeal as typewriters and they will come into their own someday. I still have a Smith-Corona cash register that I am hoping to get some basic help with (the one that was in your database for one day a few years ago).

    I think a major factor is actual utility. Some of us typewriter people have come to see the charms of sewing machines. The vintage sewing machine world is much older, bigger, and more active than the typewriter world. Reflecting on why that is, it is clear that sewing machines are more useful to real people in real life than typewriters are. Typewriters are more useful IRL than mechanical calculators are. But the calcs are even more fascinating (mechanically) than those others and so they will have a place.

    Your place in the typewriter pantheon is assured, Zeus, and there is still a lot of room on the top of Olympus for you to take on another avatar.

    1. I believe you’re very correct on the “utility” argument. Maybe Americans are just culturally inclined to value things with real-world utility and can’t be bothered with something that’s just logically entertaining and practically useless. :P

  3. I had the no duplex copy problem at one time. My files were not as long though so I sorted them manually. Nice script btw. I switched to Linux in 96 or 97 and I’ve not looked back although I was forced into Windoze at work.

    I keep the calculator files in mind just in case I ever start down the road of old mechanical calculators. They have always amazed me. Mrs. M will throw a fit!

    Stay home, stay safe, & happy scanning.

  4. Clever stuff. And I thought *I* had a scanning back log!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.