0

Treating a list from a file as an array, it can be iterated as:

PS /home/nicholas/powershell/csv> 
PS /home/nicholas/powershell/csv> $words = Get-Content ./sort.txt        
PS /home/nicholas/powershell/csv> 
PS /home/nicholas/powershell/csv> $words                         
Alpha
Hotel
Bravo
Charlie
Delta
Echo
Golf
Foxtrot
Zulu
Hotel
India
Kilo
Juliett
Lima
Mike
November
Oscar
Papa
India
Quebec
Romeo
Sierra
Tango
Charlie
Uniform
Victor
Whiskey
Alpha
X-ray
Yankee
Zulu
PS /home/nicholas/powershell/csv> 
PS /home/nicholas/powershell/csv> foreach($w in $words){echo $w} 
Alpha
Hotel
Bravo
Charlie
Delta
Echo
Golf
Foxtrot
Zulu
Hotel
India
Kilo
Juliett
Lima
Mike
November
Oscar
Papa
India
Quebec
Romeo
Sierra
Tango
Charlie
Uniform
Victor
Whiskey
Alpha
X-ray
Yankee
Zulu
PS /home/nicholas/powershell/csv> 

but how is that array sorted?

The list perhaps a bit long, just experimenting a bit with arrays and lists of data to grasp the syntax of powershell and how to use data correctly.

This data originated on a website, I put into a spreadsheet, then CSV, and am just futzing with the data.

see also:

Printing an array in Powershell

2
  • 1
    Sort-Object can be used to sort arrays, is that what you meant? Commented Jan 16, 2021 at 12:10
  • yes @GuyS that's it exactly. thanks. Commented Jan 16, 2021 at 12:17

1 Answer 1

0

per comment from Guy:

PS /home/nicholas/powershell/csv> 
PS /home/nicholas/powershell/csv> $words = Get-Content -Path ./sort.txt   
PS /home/nicholas/powershell/csv> 
PS /home/nicholas/powershell/csv> $words                               
Alpha
Hotel
Bravo
Charlie
Delta
Echo
Golf
Foxtrot
Zulu
Hotel
India
Kilo
Juliett
Lima
Mike
November
Oscar
Papa
India
Quebec
Romeo
Sierra
Tango
Charlie
Uniform
Victor
Whiskey
Alpha
X-ray
Yankee
Zulu
PS /home/nicholas/powershell/csv> 
PS /home/nicholas/powershell/csv> $words | Sort-Object                 
Alpha
Alpha
Bravo
Charlie
Charlie
Delta
Echo
Foxtrot
Golf
Hotel
Hotel
India
India
Juliett
Kilo
Lima
Mike
November
Oscar
Papa
Quebec
Romeo
Sierra
Tango
Uniform
Victor
Whiskey
X-ray
Yankee
Zulu
Zulu
PS /home/nicholas/powershell/csv> 

which works here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.