递归搜索给定名称的文件,并找到一个特定短语的实例,并显示该文件的路径 [英] Recursively search for files of a given name, and find instances of a particular phrase AND display the path to that file

查看:67
本文介绍了递归搜索给定名称的文件,并找到一个特定短语的实例,并显示该文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆的文件夹和子文件夹。各包含,除其他事项外,一个文本文件名为 index.yml 有用的数据。我想通过各种不同的 index.yml 文件搜索找到搜索字符串的实例。我必须能够看到上下文的几行和 index.yml 文件中发现的目录。

I have a bunch of folders and subfolders. Each one contains, amongst other things, a text file called index.yml with useful data. I want to search through all of the different index.yml files to find instances of a search string. I must be able to see a few lines of context and the directory of the index.yml file that was found.

这几乎是工作,但它并没有给我的文件名:

This almost works, but it doesn't give me the filename:

cat `find . -name 'index.yml'`| grep -i -C4 mySearchString

我怎么能做到这一点,得到的文件名?

How can I do this and get the filename?

我坚持在Windows上使用MSYS。请注意我似乎没有能有充分的grep GNU,所以我不能运行的grep --exclude 的grep -R 的建议在其他SO问题。

I am stuck on Windows with using msys. Note I don't seem to have full GNU grep, so I can't run grep --exclude or grep -R as suggested in other SO questions.

推荐答案

试试这个:

find -name "index.yml" -exec grep -i -H -C4 pattern {} \;

请注意:在MSYS没有实际测试过

note: not actually tested under msys.

这篇关于递归搜索给定名称的文件,并找到一个特定短语的实例,并显示该文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆