Link to home
Start Free TrialLog in
Avatar of ptea
ptea

asked on

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


Avatar of KenMcF
KenMcF
Flag of United States of America image

Try this

$Arr = "111", "21", "1111", "3"
$Arr | Sort-Object length
Avatar of ptea
ptea

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of KenMcF
KenMcF
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ptea

ASKER

thx