あなたはこのようなことを試すことができます -
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
テスト 2:
[jaypal:~/Temp] awk -v OFS="," '{print $2,$1}' <(uniq -c file)
aa,2
bb,1
cc,2
dd,1
テスト3:
[jaypal:~/Temp] while IFS=' +|,' read count text; do
echo "$text,$count";
done < <(uniq -c tmp)
aa,2
bb,1
cc,2
dd,1