Powershell sort-object

Hi there,

is it possible to use the sort-object cmdlet to sort strings depending on their length? E.g. I have these values in an Array:


111
21
1111
3

I should sort them like this:

3
21
111
1111

How to achieve that?

Cheerio


pteaAsked:
Who is Participating?
 
KenMcFCommented:
ok, that makes it a little more difficult. Given your example you could try something liek this.


Import-Csv C:\test.csv | Select a, b, c, @{n='Length';e={ ($_.a).length }} | Sort length
0
 
KenMcFCommented:
Try this

$Arr = "111", "21", "1111", "3"
$Arr | Sort-Object length
0
 
pteaAuthor Commented:
thx for your response - my description was not detailed enough, in fact the input file  (csv) looks like this:

a,b,c
111,bababa,skjskssk
11,snakj,skjasiohio
1234,cjdsh,nsuidn

I should sort the values depending on the values in the column a by the length of the string:

11,snakj,skjasiohio
111,bababa,skjskssk
1234,cjdsh,nsuidn

Cheers
0
 
pteaAuthor Commented:
thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.