【发布时间】:2021-04-20 20:04:57
【问题描述】:
我只是想计算一个单词的出现次数,而不是逐个文件地编写迭代文件。我不介意它是哪种文件。我得到的最接近的是:
COUNT=$(grep -r -n -i "theWordImSearchingFor" .)
echo $COUNT
我考虑过用空格分割,但问题是输出不仅包含文件名和行,还包含内容(可能有大量空格)。 w.g.我得到了:
./doc1.txt:29: This is the content containing theWordImSearchingFor but also other stuff
./doc1.txt:43: This is another line containing theWordImSearchingFor
./dir123/doc2.txt:339: .This is another...file...theWordImSearchingFor....
知道如何保持简单吗? TIA
【问题讨论】: