栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从bash中的文件计算单词出现

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从bash中的文件计算单词出现

好吧,我不确定您要尝试执行的操作是否正确,但是我可以这样进行:

while read filedo  cat $file | tr -cs A-Za-z' 'n'| tr A-Z a-z | sort | uniq -c > stat.$filedone < file-list

现在,您有了所有文件的统计信息,现在可以简单地对其进行汇总:

while read filedo  cat stat.$filedone < file-list | sort -k2 | awk '{if ($2!=prev) {print s" "prev; s=0;}s+=$1;prev=$2;}END{print s" "prev;}'

用法示例:

$ for i in ls bash cp; do man $i > $i.txt ; done$ cat <<EOF > file-list> ls.txt> bash.txt> cp.txt> EOF$ while read file; do> cat $file | tr -cs A-Za-z' 'n'| tr A-Z a-z | sort | uniq -c > stat.$file> done < file-list$ while read file> do>   cat stat.$file> done < file-list > | sort -k2 > | awk '{if ($2!=prev) {print s" "prev; s=0;}s+=$1;prev=$2;}END{print s" "prev;}' | sort -rn | head3875 the1671 is1137 to1118 a1072 of793 if744 and533 command514 in507 shell


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403254.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号