如何grep文件夹中的XML文件中的单词 [英] How to grep a word inside xml files in a folder

查看:127
本文介绍了如何grep文件夹中的XML文件中的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用grep来查找文件夹中存在的所有文件中的单词

I know I can use grep to find a word in all the files present in a folder like this

grep -rn core .

但是我的当前目录有很多子目录,我只想搜索所有xml存在于当前目录及其所有子目录中的文件。我怎么能这样做?

But my current directory has many sub-directories and I just want to search in all xml files present in the current directory and its all sub directories. How can I do that ?

我试过这个

grep -rn core *.xml // Does not work

但它搜索当前目录中的xml文件只要。它不会递归地执行它。

But it searches for xml files present in the current directory only. It does not do it recursively.

推荐答案

尝试--include选项

Try the --include option

grep -R --include="*.xml" "pattern" /path/to/dir

参考: Grep运行递归模式时只包含* .txt文件模式

这篇关于如何grep文件夹中的XML文件中的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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