Hi, I am a german lawstudent and have to learn a few hundred definitions and laws in the next months. I thought it would be cool to have a little helper, a bashscript which is working with flat textfiles. I found one in the archlinuxforum which was almost perfect...almost. It is on some point based on cut, so I am not able to exclude spaces as delimiters. Google said it would be better to use awk instead of cut. Problem is, this is the first bashscript I am working with and I should spend time with my lawbooks and not with scripting. It would be cool, if someone could help me.
#!/bin/bash
# flashcard program
# openning message
clear
echo "This is Matt's flashcard program."
echo "It is copyright under the GNU/GPL."
echo "Press any key to continue."
echo -n ""
read NULL
clear
DECK=$1
# Z�hle alle Karteikarten
KARTEIGROESSE=$(cat $DECK | wc -l)
# Starte die Schleife
while true ; do
# Zeige die Frage
NUMBER=$[ ( $RANDOM % $KARTEIGROESSE ) + 1 ]
ZEILE=$(cat $DECK | head -n $NUMBER | tail -n 1)
FRAGE=$(echo $ZEILE | cut -f 1 -d ">")
clear
echo "Frage: $FRAGE"
# Pr�fe die einschl�gigen Paragraphen
PARAGRAPHEN=$(echo $ZEILE | cut -f 2 -d ">" | cut -f 1 -d ">")
ANTWORT0=$(echo $ZEILE | cut -f 3 -d ">")
# Suche die korrekte ANTWORT0 der MC-Frage
OPTION=$[ ( $RANDOM % 5 ) + 1 ]
# Pr�fe, ob die Anwort richtig war
echo -n "enter PARAGRAPHEN: "
read KARTEI
for X in $(seq 1 5) ; do
if [ $X == $OPTION ] ; then
echo "$X) $ANTWORT0"
else
NUMBERX=$[ ( $RANDOM % $KARTEIGROESSE ) + 1 ]
ZEILEX=$(cat $DECK | head -n $NUMBERX | tail -n 1)
ANTWORTX=$(echo $ZEILEX | cut -f 3 -d ">")
if [ -z "$ANTWORTX" -o "$ANTWORTX" == "$FRAGE" -o "$ANTWORTX" == "$ANTWORT0" ] ; then
ANTWORTX="ZEILE $NUMBER macht whargarrgl!"
fi
echo "$X) $ANTWORTX"
fi
done
echo -n "W�hle die Antwort: "
read VERSUCH
if [ $VERSUCH == $OPTION -a $KARTEI == $PARAGRAPHEN ] ; then
clear
echo "Richtig, weiter so!"
echo -n $ZEILE
read NULL
else
clear
echo "Falsch, versuchs nochmal!"
echo -n $ZEILE
read NULL
echo $ZEILE >> wiederholen
clear
UNKNOWN=$(wc -l wiederholen | cut -f 1 -d ">")
if [ $UNKNOWN -gt 6 ] ; then
mv wiederholen $(date +%Y.%m.%d~%H.%M.%S)wiederholen
exit
fi
fi
# Beende die Schleife
done
Every line in the deck contains something like:
What should one do if the judge does X? [delimiter] � 280 Abs.1,3 i.V.m. � 281 BGB [delimiter] One should aks for Y as allowed in � 280 Abs.1,3 i.V.m. � 281 BGB. EOL
Link to original script:
http://bbs.archlinux.org/viewtopic.php?id=51375