-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessLogFile.sh
More file actions
executable file
·33 lines (33 loc) · 1.04 KB
/
processLogFile.sh
File metadata and controls
executable file
·33 lines (33 loc) · 1.04 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
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Sorry wrong input ,input must be in this form:./processLogFile.sh poll-log"
exit 1
fi
txt=$1
output="pollerResultsFile.txt"
#check if inputFile.txt exists and has read rights
if [ -e "$txt" ] && [ -r "$txt" ]; then
declare -A parties
declare -A voters
while read -r line;do
#running the inputfile and getting each element from it
name=$(echo "$line" | awk '{print $1}')
surname=$(echo "$line" | awk '{print $2}')
party=$(echo "$line" | awk '{print $3}')
if [[ " ${!voters[@]} " =~ " $name$surname " ]]; then
continue
else
#add the key in voters array if not voted yet
voters["$name$surname"]=1
#add a vote to party
((parties["$party"]++))
fi
done < "$txt"
#print results to pollerResultsFile
for party in "${!parties[@]}"; do
echo "$party ${parties[$party]}" >> "$output"
done
else
echo "Sorry file doesnt exist or it doesnt have read rights"
exit 1
fi