bash - 如何输出shell查找结果和匹配号?

标签 bash shell

我想使用find命令在文件中查找某个字符串,并希望同时查看查找结果和匹配行数。

例如,使用以下命令,我可以得到查找结果,但我不知道我得到了多少个匹配结果。

find . -name .history  | xargs grep ls

输出为

ls -r
ls -R
ls

我期望的输出是这样的

ls -r
ls -R
ls
total match number: 3

如何获得预期的输出?

最佳答案

.... | awk '{ a+=1; print} END { print "total match number: " a}'

关于bash - 如何输出shell查找结果和匹配号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10425667/

相关文章:

linux - 使用 inotifywait 并行处理两个文件

bash - "Filename argument required"从 bash_profile 运行 shell 命令时出现警告

python - 发现相似文件中的不同行

linux - 如何检查文本文件的文件夹中是否有重复的 URL

unix - 命令作为参数传递给 shell 脚本

正则表达式:匹配以 4-9 开头的数字?

bash - 如何使用 sed 在行后插入换行符/换行符

linux - 计数.sh : line 13: syntax error near unexpected token `done'

shell - 如何使用 shell 脚本附加到平面文件中的特定行

shell - 命令来验证管道中的输入然后将其传递?