Advertisement
dzocesrce

[OS] Highest Electricity Bill

Jan 20th, 2024 (edited)
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. #june 2023 exam
  2. #!/bin/bash
  3. #calculate total kWh used from the file electricity.txt for each city, and print the highest number
  4. POTROSUVACKA_BITOLA=`cat electricity.txt | grep ^[0-9] | awk -F\| 'BEGIN {total=0} $2=="Bitola" {total+=$4} END{print total}'`
  5. POTROSUVACKA_PRILEP=`cat electricity.txt | grep ^[0-9] | awk -F\| 'BEGIN {total=0} $2=="Prilep" {total+=$4} END{print total}'`
  6. POTROSUVACKA_KRIVOGASHTANI=`cat electricity.txt | grep ^[0-9] | awk -F\| 'BEGIN {total=0} $2=="Krivogashtani" {total+=$4} END{print total}'`
  7. #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
  8. if [ $POTROSUVACKA_BITOLA -gt $POTROSUVACKA_PRILEP ]
  9. then
  10.         if [ $POTROSUVACKA_BITOLA -gt $POTROSUVACKA_KRIVOGASHTANI ]
  11.         then
  12.                 echo "Najgolema potrosuvacka na struja za 2021 godina ima Bitola, i toa ${POTROSUVACKA_BITOLA} kWh!"
  13.         else
  14.                 echo "Najgolema potrosuvacka na struja za 2021 godina ima Krivogashtani, i toa ${POTROSUVACKA_KRIVOGASHTANI} kWh!"
  15.         fi
  16. elif [ $POTROSUVACKA_PRILEP -gt $POTROSUVACKA_KRIVOGASHTANI ]
  17. then
  18.         echo "Najgolema potrosuvacka na struja za 2021 godina ima Prilep, i toa ${POTROSUVACKA_PRILEP} kWh!"
  19. else
  20.         echo "Najgolema potrosuvacka na struja za 2021 godina ima Krivogashtani, i toa ${POTROSUVACKA_KRIVOGASHTANI} kWh!"
  21. fi
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement