-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbparser.sh
More file actions
30 lines (27 loc) · 901 Bytes
/
dbparser.sh
File metadata and controls
30 lines (27 loc) · 901 Bytes
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
#!/bin/bash
#assumes the list is sorted by database name
#run as ./dbparser.sh filename.csv
UNIQUE_TABLENAMES="var tableNames=["
COUNTER=1
CHECKBOXES="var checkboxes = {"
touch output.txt
while IFS=',' read -r name value
do
if ! echo $UNIQUE_TABLENAMES | tr '\"' '\n' | grep -q $name ; then
UNIQUE_TABLENAMES+="\"$name\","
CHECKBOXES+="$name : table$COUNTER, "
echo "var table$COUNTER = [\"$value\"];" >> output.txt
echo >> output.txt
((COUNTER++))
else
temp=1
temp="$(($COUNTER-$temp))"
sed -i "/var table$temp/{s/\];/,\"$value\"\];/g}" output.txt
fi
done < "$1"
UNIQUE_TABLENAMES=${UNIQUE_TABLENAMES%?}
CHECKBOXES=${CHECKBOXES%??}
UNIQUE_TABLENAMES+="];"
CHECKBOXES+="};"
echo $UNIQUE_TABLENAMES >> output.txt
echo $CHECKBOXES >> output.txt