
有一列数据的文件,想计算每行数据的重复次数时可以用sort和uniq进行计数:
#cat file
hello
world
friend
hello
world
hellosort file |uniq -c 但是当文件过大时,会报错,显示空间不足: sort: write failed: /tmp/sortbDyE0W: No space left on device
这个时候可以通过awk来进行计数:
cat file | awk '{count[$1]++;} END {for(i in count) {print i count[i]}}'