$a | sort { $_.value.length } | select -expand value -first 1
how to sort objects by value length in powershell
-
22-07-2023 - |
Question
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
Solution
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow