sed '1d'|awk 'BEGIN{FS=";";sum=0} {sum+=$3; avg=sum/NR; if($3<avg) print $3}'
This is the unix command I tried for printing the salary of employees having salary less than the average salary of all the employees. The Input given was:
Empid;Empname;Salary
101;V;30000
102;A;45000
103;I;15000
104;S;40000
According to the input the average salary= 32500 which means 30000, 15000 both should be displayed in the output. But I can only get 15000 as my output. Please help and tell where am i going wrong.