我可以使用Select-String返回一个文件列表,其中包含一些我正在查找的文本:
Get-ChildItem *.cs -recurse | Select-String -SimpleMatch ".ToList()" | group path | select name我要做的是对查询结果应用后续过滤器。我想做一些类似的事情:
if($fileSet -eq $null)
{
$fileSet = Get-ChildItem *.cs -recurse | Select-String -SimpleMatch ".ToList()" | group path | select name
}
$fileSet | Select-String -SimpleMatch "Additional Term" | group path | select name我认为我需要一种方法来将文件数组($fileSet)的内容通过管道传递给Select-String;然而,我非常确定我做错了。感谢任何人的帮助!
发布于 2019-07-25 03:23:49
不如这样吧:
Get-ChildItem *.cs -Recurse | Select-String -SimpleMatch ".ToList()" | ForEach-Object {
$_ | Select-String -SimpleMatch "Additional Term"
} | Group-Object Path | Select-Object -ExpandProperty Name发布于 2019-07-25 04:28:06
我能够修改被接受的答案,以保持问题中类似的结构。
if($fileSet -eq $null)
{
$fileSet = Get-ChildItem *.cs -recurse | Select-String -SimpleMatch ".ToList()"
}
$fileSet | foreach {
Select-String -Path $_.Path -SimpleMatch "Additional Term"
} | Group-Object Path | Select-Object -ExpandProperty Namehttps://stackoverflow.com/questions/57187398
复制相似问题