I am beginner to awk. I have created one file which contains employee information. There are employees in different departments. And i wanna count that how many employees in each department. like
marketing 3
sales 3
production 4
For that i used following command.
awk 'NR>1 {dept=$5} {count[dept]++} END {for (dept in count) {print dept count[dept]}}' emp
But above code it count and displays the first line i.e header also. like
marketing 3
sales 3
department 1
production 4
where department is a header of column which is also counted although i used NR>1.. And how to add space or increase the width of all columns.. because it looks like above output.. but i wanna display it properly.. So any solution for this?
Here is my input file
empid empname department
101 ayush sales
102 nidhi marketing
103 priyanka production
104 shyam sales
105 ami marketing
106 priti marketing
107 atuul sales
108 richa production
109 laxman production
110 ram production
NR>1{count[$5]++}END{yadayda}
– Pruritus