Awk: Characters-frequency from one text file?

穿精又带淫゛_ 提交于 2019-12-04 18:14:54

One method:

$ grep -o '\S' file | awk '{a[$1]++}END{for(k in a)print a[k],k}' 
3 옥
4 h
2 u
2 i
3 B
5 !
2 w
4 爸
1 군
4 지
1 y
2 l
1 E
1 會
2 你
1 是
2 a
1 不
2 이
2 o
1 p
2 的
1 d
1 생
3 r
6 e
4 s
1 我
4 t

Use redirection to save the output to a file:

$ grep -o '\S' file | awk '{a[$1]++}END{for(k in a)print a[k],k}' > output

And for sorted output:

$ grep -o '\S' file | awk '{a[$1]++}END{for(k in a)print a[k],k}' | sort > output
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!