Reading and analysing data in a text file

Hi,
I have below type of data in a text file in unix.
Emp_Name Emp_Dept
Raj 101
Amruta 100
Shilpa 100
Rohit 123
Amol 198
Rosh 101
Gaurav 198

Number of employees can be even more.
Need a command or a shell script which gives the output as dept number and no. of employees in individual department.
For eg
100 2

cat inputfile | cut -f2 | uniq | while read line
do
set `grep " $line" file | wc -l`
echo "$line $1" >> outputfile
done
1 Like

This could be done with an one liner in awk using associative arrays. Please search the forum.

1 Like