This repository has been archived by the owner on Jan 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·71 lines (61 loc) · 2.14 KB
/
run.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VMARC="$1"
OUTDIR="$2"
FILTERDIR="$3"
if [ "$VMARC" != "" ] && [ ! -f "$VMARC" ]; then
echo "'$VMARC' finnes ikke"
fi
if [ "$OUTDIR" != "" ] && [ ! -d "$OUTDIR" ]; then
echo "'$OUTDIR' finnes ikke"
fi
if [ "$FILTERDIR" != "" ] && [ ! -d "$FILTERDIR" ]; then
echo "'$FILTERDIR' finnes ikke"
fi
if [ ! -f "$VMARC" ] || [ ! -d "$OUTDIR" ] || [ ! -d "$FILTERDIR" ]; then
echo "bruk: ./run.sh </path/to/data.vmarc.txt> <output_dir> <filter_dir>"
exit 1
fi
GENRE_TEMP_MARC="/tmp/genre.marc"
GENRE_TEMP_CSV="/tmp/genre.csv"
echo "lager $GENRE_TEMP_MARC..."
cat "$VMARC" | grep "^.\(001\|245\|592\|655\)" > $GENRE_TEMP_MARC
echo "lager $GENRE_TEMP_CSV..."
if [ -f "$GENRE_TEMP_CSV" ]; then
rm "$GENRE_TEMP_CSV"
fi
IDENTIFIER=""
TITLE=""
AVAILABLE=""
GENRE=""
TOTAL_BOOKS="`cat "$VMARC" | grep "^.\(001\)" | wc -l`"
COUNT=0
while read line; do
TAG="`echo $line | sed 's/^.\(...\).*$/\1/'`"
if [ "$TAG" = "001" ]; then
BOOK_COUNTER=$((BOOK_COUNTER+1))
if [ "$(($BOOK_COUNTER % 1000))" = "0" ]; then
echo "$BOOK_COUNTER av $TOTAL_BOOKS katalogposter behandlet"
fi
if [ "$IDENTIFIER" != "" ]; then
echo "\"$GENRE\",\"$IDENTIFIER\",\"$TITLE\",\"$AVAILABLE\"" >> $GENRE_TEMP_CSV
IDENTIFIER=""
TITLE=""
AVAILABLE=""
GENRE=""
fi
IDENTIFIER="`echo $line | sed 's/^....0*//' | sed 's/"/""/g'`"
elif [ "$TAG" = "245" ]; then
TITLE="`echo $line | grep '\$a' | sed 's/.*\$a//' | sed 's/\$.*//' | sed 's/"/""/g'`"
elif [ "$TAG" = "592" ]; then
AVAILABLE="`echo $line | grep '\$a' | sed 's/.*\$a//' | sed 's/\$.*//' | sed 's/"/""/g'`"
elif [ "$TAG" = "655" ]; then
GENRE="`echo $line | grep '\$a' | sed 's/.*\$a//' | sed 's/\$.*//' | sed 's/"/""/g'`"
fi
done < "$GENRE_TEMP_MARC"
if [ "$IDENTIFIER" != "" ]; then
echo "\"$GENRE\",\"$IDENTIFIER\",\"$TITLE\",\"$AVAILABLE\"" >> $GENRE_TEMP_CSV
fi
echo "lager XML..."
python3 $DIR/build-xml.py "$GENRE_TEMP_CSV" "$OUTDIR" "$FILTERDIR"
echo "Sjanger-XML ligger nå ferdig i '$OUTDIR'."