PowerShell相当于grep -f [英] PowerShell equivalent to grep -f
本文介绍了PowerShell相当于grep -f的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找相当于 grep --file = filename
的PowerShell。如果您不知道 grep
,则filename是一个文本文件,其中每行都有您想要匹配的正则表达式模式。
也许我错过了一些显而易见的东西,但是 Select-String
似乎没有这个选项。
Select-String 中的
-Pattern
参数支持一个数组的模式。所以你要找的是: Get-Content .\doc.txt | Select-String -Pattern(Get-Content .\regex.txt)
这将搜索文本文件 doc.txt
通过使用 regex.txt中的每个正则表达式(每行一个)
I'm looking for the PowerShell equivalent to grep --file=filename
. If you don't know grep
, filename is a text file where each line has a regular expression pattern you want to match.
Maybe I'm missing something obvious, but Select-String
doesn't seem to have this option.
解决方案
The -Pattern
parameter in Select-String
supports an array of patterns. So the one you're looking for is:
Get-Content .\doc.txt | Select-String -Pattern (Get-Content .\regex.txt)
This searches through the textfile doc.txt
by using every regex(one per line) in regex.txt
这篇关于PowerShell相当于grep -f的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文