Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #june 2023 exam
- #!/bin/bash
- #calculate total kWh used from the file electricity.txt for each city, and print the highest number
- POTROSUVACKA_BITOLA=`cat electricity.txt | grep ^[0-9] | awk -F\| 'BEGIN {total=0} $2=="Bitola" {total+=$4} END{print total}'`
- POTROSUVACKA_PRILEP=`cat electricity.txt | grep ^[0-9] | awk -F\| 'BEGIN {total=0} $2=="Prilep" {total+=$4} END{print total}'`
- POTROSUVACKA_KRIVOGASHTANI=`cat electricity.txt | grep ^[0-9] | awk -F\| 'BEGIN {total=0} $2=="Krivogashtani" {total+=$4} END{print total}'`
- #I suppose there are no 2 cities tied as far as kWh usage goes, but if there are then we have more ifs, butts & maybz
- if [ $POTROSUVACKA_BITOLA -gt $POTROSUVACKA_PRILEP ]
- then
- if [ $POTROSUVACKA_BITOLA -gt $POTROSUVACKA_KRIVOGASHTANI ]
- then
- echo "Najgolema potrosuvacka na struja za 2021 godina ima Bitola, i toa ${POTROSUVACKA_BITOLA} kWh!"
- else
- echo "Najgolema potrosuvacka na struja za 2021 godina ima Krivogashtani, i toa ${POTROSUVACKA_KRIVOGASHTANI} kWh!"
- fi
- elif [ $POTROSUVACKA_PRILEP -gt $POTROSUVACKA_KRIVOGASHTANI ]
- then
- echo "Najgolema potrosuvacka na struja za 2021 godina ima Prilep, i toa ${POTROSUVACKA_PRILEP} kWh!"
- else
- echo "Najgolema potrosuvacka na struja za 2021 godina ima Krivogashtani, i toa ${POTROSUVACKA_KRIVOGASHTANI} kWh!"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement