8 ms·
And the best bit about PowerShell is that you don't have to force everything into text, and then work out how to parse it back out of text. You are in a script
by jodrellblank 8y ago
And the best bit about PowerShell is that you don't have to force everything into text, and then work out how to parse it back out of text.
You are in a scripting language REPL where you can have a hashtable of words and their counts, and keep it structured
gc words.txt |% { -split $_ } | group | sort count -desc | select -first 5
and when I saw the first one was spaces:
gc words.txt |% { -split $_ -match '^\w+$' } | group | sort count -desc | select -first 5
But the point isn't that you can do it, or any comment on the length of it, the point is that the output of group (group-object) is structured - the counts are [int] types, the sort is able to pick those out and sort on them without needing to parse them out of text and convert them to numbers, the select (select-object) isn't outputting individual lines of text, so the structure isn't lost when shown on screen, and the output can be formatted for display as columns, lists, tables, from its structure.