Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -ne 1 ]
- then
- echo "USAGE: `basename $0` mesec"
- exit 1
- fi
- MONTH=$1
- total_electricity=`cat electricity.txt | grep "|$MONTH|" | awk -F\| 'BEGIN {total=0} {total+=$5} END {print total}'`
- number_people=`cat electricity.txt | grep "|$MONTH|" | wc -l`
- if [ $number_people -eq 0 ]
- then
- echo "Nema podatoci za toj mesec"
- exit $1
- fi
- average_electricity=`expr $total_electricity / $number_people`
- touch people.txt
- #just testing if I can put a shell variable into an awk command.
- #it looks good on paper, but unfortunately all I have is a laptop
- echo "`cat electricity.txt | grep "|$MONTH|" | awk -var $average_electricity '$3>$var {print $1 $2}'`" >> people.txt
- cat people.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement