美文网首页
对大文件字符进行计数

对大文件字符进行计数

作者: 生信编程日常 | 来源:发表于2020-10-04 23:15 被阅读0次

有一列数据的文件,想计算每行数据的重复次数时可以用sort和uniq进行计数:

#cat file
hello
world
friend
hello
world
hello
sort 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]}}' 

参考:https://www.cnblogs.com/hider/p/11834706.html

相关文章

网友评论

      本文标题:对大文件字符进行计数

      本文链接:https://www.haomeiwen.com/subject/imeouktx.html