$a | sort { $_.value.length } | select -expand value -first 1
how to sort objects by value length in powershell
-
22-07-2023 - |
Frage
how can I get the object with smaller name size from an array?
$a
Name Value
---- -----
name A
name AAAA
name BB
name AAAAAA
$a | get-smaller -property "name" ==> should return the object with name = A
thanks
Lösung
Andere Tipps
To sort file input.txt by lines length and put the result to output.txt:
Get-Content -Path input.txt | sort { $_.length } > output.txt
- Result is not ASCII/case-sensitive sorted
- There might be problem with different encodings - lines are omitted
- Result is normally UCS-2 Little Endian
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow