我想帮助我的女朋友 - 她需要200个文件(每个文件)中特定字符的具体计数。使用unix shell计算多个文件中字符的出现次数
我已经找到How can I use the UNIX shell to count the number of times a letter appears in a text file?,但只显示完整的数字,而不是每个文件的出现次数。基本上,我想要的是以下内容:
$ ls
test1 test2
$ cat test1
ddddnnnn
ddnnddnnnn
$ cat test2
ddnnddnnnn
$ grep -o 'n' * | wc -w
16
$ <insert command here>
test1 10
test2 6
$
或类似的输出。因为这将在她的大学机器上,我不能在perl中编写任何代码,所以只允许shell。我的外壳知识有点生疏,所以我不能想出更好的解决方案 - 也许你可以提供帮助。
'用于*'文件移位6优选'在$(LS)文件' - http://mywiki.wooledge.org/ParsingLs – 2012-03-31 17:28:49
对,纠正,thx,+1 – tchap 2012-03-31 19:47:11