如何在powershell中按值长度对对象进行排序

时间:2014-05-14 02:09:46

标签: powershell

如何从数组中获取名称较小的对象?

$一个

名称值
---- -----
名称A
名称AAAA
名称BB
名称AAAAAA

$ a | get-smaller -property" name" ==>应返回name = A

的对象

感谢

2 个答案:

答案 0 :(得分:7)

$a | sort { $_.value.length }  | select -expand value -first 1

答案 1 :(得分:0)

To sort file input.txt by lines length and put the result to output.txt:

Get-Content -Path input.txt | sort { $_.length } > output.txt
  1. Result is not ASCII/case-sensitive sorted
  2. There might be problem with different encodings - lines are omitted
  3. Result is normally UCS-2 Little Endian