2016-10-28 13 views
1

我试图在我们的源代码控制文件(1000年)中找到所有SQL Server对象名称(大约800)。当我尝试使用Select-String它会找到一个字符串,但它会停止处理它找到匹配的行上的文件。这是我得到的一个小样本。它应该返回'was'的匹配。使用PowerShell在文本文件的同一行上查找多个字符串Select-String

Use the Select-String cmdlet to process both of the words 'test' and 'was' in the same sentence and all it returns is the matches for 'test'. 

('This is a test. How was your test?' | Select-String -Pattern @('test','was') -AllMatches).Matches 

Groups : {0} 
Success : True 
Name  : 0 
Captures : {0} 
Index : 10 
Length : 4 
Value : test 

Groups : {0} 
Success : True 
Name  : 0 
Captures : {0} 
Index : 29 
Length : 4 
Value : test 

回答

1

可以通过使用正则表达式,而不是一个字符串数组的实现此目的:

('This is a test. How was your test?' | Select-String -Pattern '\btest\b|\bwas\b' -AllMatches).Matches 
相关问题