我有一个文件,list.txt
其中包含一个单词列表.我想检查每个单词出现在另一个文件中的次数file1.txt
,然后输出结果.所有数字的简单输出就足够了,因为我可以手动将它们添加到list.txt
电子表格程序中,但如果脚本在每行的末尾添加数字list.txt
,那就更好了,例如:
bear 3
fish 15
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它不起作用:
cat list.txt | grep -c file1.txt
Run Code Online (Sandbox Code Playgroud)
您可以在循环中执行此操作,该循环一次从单词列表文件读取单个单词,然后计算数据文件中的实例.例如:
while read; do
echo -n "$REPLY "
fgrep -ow "$REPLY" data.txt | wc -l
done < <(sort -u word_list.txt)
Run Code Online (Sandbox Code Playgroud)
"秘密酱"包括: