script.sh
1.77 KB
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
cut -d ";" -f 4 data/*.csv | sort | uniq > data/theme.txt
THEMES=$(cat data/theme.txt | tr "\n" ",")
CATEGORIES=$(grep -o -E "^[^(]*" categorie.txt | sed "s/ $//" | tr "\n" ",")
THEMES=$(echo $THEMES | sed "s/,/\",\"/g" | sed "s/^/\"/" | sed "s/,\"$//")
CATEGORIES=$(echo $CATEGORIES | sed "s/,/\",\"/g" | sed "s/^/\"/" | sed "s/,\"$//")
echo $THEMES > data/csv.theme
echo $CATEGORIES > data/csv.cat
for FORMATION in $(ls data/*.csv)
do
echo -n $FORMATION
echo -n -e " ("
echo -n $(cut -d ";" -f 3 $FORMATION | paste -sd+ | bc)
echo " ECTS)"
> $FORMATION.theme
> $FORMATION.cat
echo -e "\tPar thème"
IFS=''
cat data/theme.txt |
while read THEME
do
echo -n -e "\t\t$THEME "
ECTS=$(grep $THEME$ $FORMATION | cut -d ";" -f 3)
if [[ -z "$ECTS" ]]
then
ECTS=0
fi
ECTS=$(echo $ECTS | tr ' ' '\n' | paste -sd+ | bc)
THEMES_ECTS=$THEMES_ECTS,$ECTS
echo -n "$ECTS," >> $FORMATION.theme
echo $ECTS
done
sed -i "s/,$/\n/" $FORMATION.theme
echo -e "\tPar catégorie"
IFS=''
cat categorie.txt |
while read CAT
do
CATEGORIE=$(echo $CAT | grep -o -E "^[^(]*")
PATT=$(echo $CAT | grep -o "(.*)")
echo -n -e "\t\t$CATEGORIE"
ECTS=$(grep -E $PATT$ $FORMATION | cut -d ";" -f 3 | paste -sd+ | bc)
echo -n "$ECTS," >> $FORMATION.cat
echo $ECTS
done
sed -i "s/,$/\n/" $FORMATION.cat
done
# Generate web page with graphical results
cp www/programme.template www/programme.html
IFS=$'\n'
for FILE in $(ls -1 data)
do
if [ $(grep "\[$FILE\]" www/programme.html | tr -d '\n') ]
then
sed -i "s/\[$FILE\]/[$(head -c -1 -q data/$FILE)]/g" www/programme.html
fi
done