To count songs by artist, from a file containing a list of filenames with format C:\blah\blah\bling\99 Artist - Song.mp3
get-content \0.txt
| foreach-object -process {
if ($_ -match "\\\d\d ([^\\]+) -") {$_ = $matches[1] }
else {$_ = "X"}; $_
| group-object
| sort-object -property count
}
- the count property belongs to the objects that group-object produces
- the -process part of foreach-object doesn't output anything by default, hence the trailing $_
- $matches[n] == $n in Perl