#!/bin/bash
# 
# $1: notes file
# $2: subject
#
# File format ->  student:subject:grade

if [ $# -ne 2 ]
then echo "Wrong number of parameters"; exit
fi

if [ ! -f $1 ]
then echo $1 "not a regular file"; exit 
fi

# 2 best grades for subject $2
echo "2 best grades for " $2 
grep $2 $1 | sort -nrt: -k3 | head -n2
echo 

# 3 worst grades for subject $2
echo "3 worst grades for" $2 
grep $2 $1 | sort -nrt: -k3 | tail -n3 
echo 

# student with best grade
echo "Student with highest grade:"
sort -nrt: -k3 $1 | head -n1 | cut -d: -f 1,3
echo

# subject with best grade
echo "Subject with best grade:"
sort -nrt: -k3 $1 | head -n1 | cut -d: -f 2,3