简体   繁体   中英

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.

    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

输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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