-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·64 lines (46 loc) · 1.25 KB
/
script.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
#!/bin/bash
output="data.js"
#output="/dev/stdout"
echo "var morganeData = [{" > $output
COUNTER=0
while read line
do
country=`echo $line | cut -d ',' -f 1` >> $output
country=${country}
echo "Country: $country"
if [[ -z "${country}" ]]
then
continue
else
let COUNTER+=1
code=`grep "$country" ./js/morgane_data.js -B1 | head -n 1 | cut -d '"' -f 4`
if [[ -z $code ]]
then
echo "Couldn't find the code -aborting"
break
fi
echo "\"code\": \"$code\"," >> $output
echo "\"name\": \"$country\"," >> $output
fi
for i in {1..7}
do
let j=$i+1
echo $line
category=`echo $line | cut -d ',' -f $j` >> $output
#remove whitespaces, end of line characters etc.
category=${category//[^[:alnum:]]/}
echo "category: ${category}#"
if [[ $category == "1" ]]
then
echo "cat${i}:1"
echo "\"cat${i}\": \"1\"," >> $output
else
echo "cat${i}:0"
echo "\"cat${i}\": \"0\"," >> $output
fi
done
echo "}, {" >> $output
done <$1
sed -i '$ d' $output
echo "}];" >> $output
(>&2 echo "Found $COUNTER countries - success")