我正在寻找与grep --file=filename
等同的PowerShell。如果您不知道grep
,那么filename是一个文本文件,其中每一行都有一个您想要匹配的正则表达式模式。
也许我遗漏了一些明显的东西,但Select-String
似乎没有这个选项。
发布于 2013-03-04 20:06:58
Select-String
中的-Pattern
参数支持模式数组。所以你要找的是:
Get-Content .\doc.txt | Select-String -Pattern (Get-Content .\regex.txt)
这将使用regex.txt
中的每个正则表达式(每行一个)来搜索文本文件doc.txt
发布于 2014-01-04 10:48:56
PS) new-alias grep findstr
PS) C:\WINDOWS> ls | grep -I -N exe
105:-a--- 2006-11-02 13:34 49680 twunk_16.exe
106:-a--- 2006-11-02 13:34 31232 twunk_32.exe
109:-a--- 2006-09-18 23:43 256192 winhelp.exe
110:-a--- 2006-11-02 10:45 9216 winhlp32.exe
PS) grep /?
发布于 2013-03-04 19:28:45
我不熟悉grep,但是使用Select-String可以做到:
Get-ChildItem filename.txt | Select-String -Pattern <regexPattern>
你也可以用Get-Content做到这一点:
(Get-Content filename.txt) -match 'pattern'
https://stackoverflow.com/questions/15199321
复制相似问题