Вы можете попробовать что-то вроде этого -
awk '{a[$1]++}END{for (i in a) print i,a[i] | "sort"}' OFS="," filename
или
awk -v OFS="," '{print $2,$1}' <(uniq -c file)
или
uniq -c file | awk '{printf("%s,%s\n",$2,$1)}'
или
while IFS=' +|,' read count text; do
echo "$text, $count";
done < <(uniq -c tmp)
Тест:
[jaypal:~/Temp] cat file
aa
aa
bb
cc
cc
dd
[jaypal:~/Temp] awk '{a[$1]++}END{for (i in a) print i,a[i] | "sort"}' OFS="," file
aa,2
bb,1
cc,2
dd,1
Test2:
[jaypal:~/Temp] awk -v OFS="," '{print $2,$1}' <(uniq -c file)
aa,2
bb,1
cc,2
dd,1
Test3:
[jaypal:~/Temp] while IFS=' +|,' read count text; do
echo "$text,$count";
done < <(uniq -c tmp)
aa,2
bb,1
cc,2
dd,1