Reputation: 25
I've just started using awk,
so this is the input
No | Band
1 | 2G
2 | 3G
3 | 4G
4 | 2G
5 | 2G
and the output is
Band | Sum
2G | 3
3G | 1
4G | 1
Thank you very much
Upvotes: 1
Views: 51
Reputation: 37288
Try this
echo "No | Band
1 | 2G
2 | 3G
3 | 4G
4 | 2G
5 | 2G "\
| awk -F'|' 'NR>1{
band[$2]++
}
END{
print "Band | Sum"
for (x in band){
print x" | " band[x]
}
}'
output
Band | Sum
3G | 1
2G | 3
4G | 1
Upvotes: 2
Reputation: 249293
tail -n +2 input.txt | cut -d'|' -f2 | sort | uniq -c
3 2G
1 3G
1 4G
Upvotes: 2