cat nowcoder.txt|xargs -n 1|sort -n|uniq -c|sort -n|awk '{print $2,$1}'
###思路:
xargs -n 1 表示拆分为1列
sort -n 按照数字排序
uniq -c 统计每行出现的次数
awk '{print $2,$1}' 调整打印的顺序(相当于去掉了前面的长空白部分),下面示例:
[vm_1]# cat nowcoder.txt|xargs -n 1|sort -n|uniq -c|sort -n
1 to
2 welcome
3 nowcoder
[vm_1]# cat nowcoder.txt|xargs -n 1|sort -n|uniq -c|sort -n|awk '{print $2,$1}'
to 1
welcome 2
nowcoder 3



京公网安备 11010502036488号