Skip to content

Instantly share code, notes, and snippets.

@alirezaomidi
Last active August 29, 2015 14:20
Show Gist options
  • Save alirezaomidi/211c60de138a1f4f8661 to your computer and use it in GitHub Desktop.
Save alirezaomidi/211c60de138a1f4f8661 to your computer and use it in GitHub Desktop.
Scanner output sorter
#!/bin/bash
# Sorts the images which are scanned by a scanner in the following way: (last file index is 20 for e.g.)
# pages 1,3,5,... are named scan0000.jpg, scan0001.jpg, scan0002.jpg,...
# then pages 2,4,6,... are named scan0020.jpg, scan0019.jpg, scan0018.jpg, ...
# The script sorts them in range 000 to 020
mkdir -p final
end=`ls scan* -1 | wc -l`
flag=0
for i in `eval echo {000..$((end-1))}`; do # max range = 999; add more 0 for more range
if ((flag%2==0)); then
mv `ls scan* -1 | head -n1` "final/scan$i.jpg"
else
mv `ls scan* -1 | tail -n1` "final/scan$i.jpg"
fi
((flag++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment