#!/bin/bash
# Count repeated, input a sorted file, output sorted count
# -n for numbers fisrt

if [ $# -eq 1 ]
	then 
		file="$1"
		flag=0
	else 
		file="$2"
		flag=1
fi

first=`head -1 $file`
n=0
cat $file | while read second
do
	if [ "$first" = "$second" ]
		then
			((n++))
		else
			if [ $flag = 0 ]
				then
					echo "$first $n"
				else
					echo "$n $first"
			fi
			n=1
			first="$second"
	fi
done
				