Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

using awk and cat and grep

# get cities as unique form 
uniq=$( cat $1 |awk -F "," '{print $2}' | sort -u)

## loop in the list of uniq cities 
for UniqCity in $uniq ; do

          # grep all field where city appears 
                                ## sort according to temporary from bigger to smaller 
                                           #take the 3rd column{temporary} 
                                                          # take the larger temporary which appears and the first line
  maxTemp=$(grep $UniqCity $1 | sort -nr | cut -f3 -d"," | head -n1  )
  # count number of lines 
  lines=$(cat $1 | wc -l)

  # sum of temporary according to city 
  Total=$(grep $UniqCity $1| awk -F "," '{print $3}'  | awk '{s+=$1} END {print  s}')

  avg=$(expr $Total / $lines) 
  echo "City:$UniqCity"
  echo "max: $maxTemp"
  echo "avg: $avg"
 
 
PREVIOUS NEXT
Tagged: #awk #cat #grep
ADD COMMENT
Topic
Name
7+3 =