简体   繁体   English

使用grep在多个文件中查找字符串

[英]Find a string in multiple files using grep

I have a folder with sub-folders inside, all have many types of files. 我有一个里面有子文件夹的文件夹,都有很多类型的文件。 I want to search for a word inside the .css -files. 我想在.css -files中搜索一个单词。 I am using Windows 7 and I have grep . 我使用的是Windows 7,我有grep

How I can use grep to : 我如何使用grep

  1. Find pattern and print it 找到图案并打印出来
  2. Give file name (and path) if pattern found 如果找到模式,则提供文件名(和路径)

Actually you don't need find . 其实你不需要find Just use: 只需使用:

grep -R --include=*.css -H pattern .

this will recurse and look for all *.css in subdirectories, while -H will show the filename. 这将递归并查找子目录中的所有* .css,而-H将显示文件名。

find folder/ -name "*.css" |xargs grep "your-pattern"

You will need to install cygwin to do this. 您需要安装cygwin才能执行此操作。

if the files in which we have to look for, has pattern then we can use this. 如果我们要查找的文件有模式,那么我们可以使用它。 Consider I'm looking for pattern "cardlayout" in files named chap1.lst chap2.lst and so on. 考虑我在名为chap1.lst chap2.lst文件中寻找模式“cardlayout”,依此类推。 then the command 那么命令

grep -e 'cardlayout' ` find . -name "chap??.lst"`

hope this would help 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM