I have an input CSV file with a column containing information similar to the sample below:
805265
995874
805674
984654
332574
339852
I’d like to extract unique values into a array based on the leading two characters, so using the above sample my result would be:
80, 99, 98, 33
How might I achieve this using PowerShell?
I’d use the
Group-Objectcmdlet (aliasgroup) for this:Import-Csv foo.csv | group {$_.ColumnName.Substring(0, 2)} Count Name Group ----- ---- ----- 2 80 {805265, 805674} 1 99 {995874} 1 98 {984654} 2 33 {332574, 339852}