如何根据文件名对Powershell选择字符串输出进行分组

我正在使用以下Powershell命令...根本不是专家,所以愿意尝试不同的方法。

    select-string -path *.html -pattern $pattern -allmatches |
foreach-object {write-host $_.filename; $_.matches} | 
foreach-object {$_.groups[1].value}

我想将属于文件

的所有匹配项分组
filename.html
  match
  match
filename2.html
  match 

以此类推...

我可以使用上面的方法来执行此操作吗?如果没有,您能建议一种更好的方法吗?

谢谢!

w5201021965 回答:如何根据文件名对Powershell选择字符串输出进行分组

请在下面找到命令列表,以将带有扩展名的文件分组在一个文件夹中

$files = Get-ChildItem -Path "Source Directory Path"-Recurse
$files | Group-Object -Property Extension
write-host $files

Output

本文链接:https://www.f2er.com/3148037.html

大家都在问