如何在unix中从文本文件中查找特定单词的出现次数
我有一个文本文件,其中有17000行,例如:如何在unix中从文本文件中查找特定单词的出现次数,unix,Unix,我有一个文本文件,其中有17000行,例如: another instance started another instance started instance not started bss instance started 像这样 我必须找到单词“另一个”在上面例子中的打印次数,我的输出应该是2。对于上面的示例,我需要shell脚本命令。有谁能帮我编写shell代码或命令吗?只要使用好的grep就行了 grep -c 'word' file 首先,你应该努力寻找,答案很容易找到 第二
another instance started
another instance started
instance not started
bss instance started
像这样
我必须找到单词“另一个”在上面例子中的打印次数,我的输出应该是2。对于上面的示例,我需要shell脚本命令。有谁能帮我编写shell代码或命令吗?只要使用好的grep就行了
grep -c 'word' file
首先,你应该努力寻找,答案很容易找到 第二:
grep -c another yourfilepath
grep-c flip article.txt
十,
看
和\是一个单词边界,它与abcanother或anotherxyz等不匹配。
grep-o'\'file.txt|wc-l
请添加您尝试过的内容。大多数人都想帮忙,而不是做你的工作。对不起,我是unix新手,所以我没有尝试任何我需要的答案来尝试的东西,并将尝试根据答案来提高我的技能。作为新手没有什么错。但是试着在询问之前搜索一下。谷歌是你的朋友。这将提高你的下一个问题被投票的几率。希望我们能帮忙。请随意接受答案。谢谢你的肯定回答。我会在尝试后张贴我的疑问
\<another\> is a word boundary and it won't match abcanother or anotherxyz etc.
grep -o '\<another\>' file.txt | wc -l