简体   繁体   English

如何根据文件名对 powershell 选择字符串 output 进行分组

[英]How to group powershell select-string output based on filename

I'm using the following Powershell command... not an expert at all, so willing to try different ways.我正在使用以下 Powershell 命令......根本不是专家,所以愿意尝试不同的方式。

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

I would like to group all of the matches belonging to a file like我想对属于一个文件的所有匹配项进行分组,例如

filename.html
  match
  match
filename2.html
  match 

and so on...等等...

Can I do this using the approach above, if so, how?我可以使用上面的方法做到这一点,如果可以,怎么做? If not, could you suggest a better way?如果没有,你能推荐一个更好的方法吗?

Thank you!谢谢!

Please find the list of commands below to group the files with the extensions in a folder请在下面找到命令列表,以将具有扩展名的文件分组到文件夹中

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

输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM