summaryrefslogtreecommitdiff
path: root/fixoverwiped.sh
blob: 199b4a041731c04bc3adf58939cdfab89cbda0dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
usage="Usage: $0 overwipedfile origdir nowipedir newdir"
test $# -ne 4 && echo "$usage" && exit 1

overwiped="$1"
origdir="$2"
nowipedir="$3"
newdir="$4"

if ! test -f "$1"; then
	echo "Error: no overwiped file found"
	exit 1
fi

for i in "$origdir" "$nowipedir"; do
	if ! test -d "$i"; then
		echo "Error: no directory "$i" found"
		exit 1
	fi
done

if test -d "$newdir"; then
	echo "Error: directory $newdir exists"
	exit 1
fi

cp -r "$origdir" "$newdir"

while read i; do
	pgnum=`echo "$i" | awk '{print $1}'`
	badone=`echo "$i" | awk '{print $8}' | sed 's/[()]//g'`
	goodone=`find "${nowipedir}/best" -type f -name "${pgnum}*hocr"|head -n 1|sed 's/.*_bin/bin/;s/.hocr$//'`

	rm "$newdir/${pgnum}_${goodone}.png"
	cp "$nowipedir/${pgnum}_${goodone}.png" "$newdir"

	rm "$newdir/best/${pgnum}_${badone}.hocr"
	cp "$nowipedir/${pgnum}_${goodone}.hocr" "$newdir/best"
done < "$overwiped"

echo "All done. Hopefully $newdir/best should be great now"