简体   繁体   English

在Windows中使用特定文件扩展名的文件中刷一个单词

[英]Grep a word in files with specific file extension in windows

I would use the following command to grep a text in a directory with many files. 我将使用以下命令来grep具有许多文件的目录中的文本。

grep -irl "SampleText" *.txt

My case is to grep only in .txt files. 我的情况是只在.txt文件中grep。 While executing the above command in command prompt of windows it throws an error like 在Windows的命令提示符中执行上述命令时,会抛出一个错误

grep: *.txt: Invalid argument

Did I miss something? 我错过了什么?

Use: 采用:

grep --include=*.txt -irl . -e "SampleText"

remove the l argument to print the text and it's surrounding text too 删除l参数以打印文本,它也是周围的文本
and add the n argument to see the line number of the text you found 并添加n参数以查看找到的文本的行号

Use man grep for further info 使用man grep获取更多信息

使用内置实用程序?

findstr /s /i /m "SampleText" *.txt

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

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