![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Sorting (again) I have something like: PS C:\> gc tmp.csv User1,50 User3,100 User1,20 User1,100 I want to sort on the 1st column *and* 2nd column PS C:\> gc tmp.csv|sort User1,100 (<--wrong!) User1,20 User1,50 User3,100 Do I have to create objects? Marco |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Sorting (again) "Marco Shaw" <marco@Znbnet.nb.ca> wrote in message news:uAW7sM3CHHA.4256@TK2MSFTNGP04.phx.gbl... >I have something like: > PS C:\> gc tmp.csv > User1,50 > User3,100 > User1,20 > User1,100 > > I want to sort on the 1st column *and* 2nd column > PS C:\> gc tmp.csv|sort > User1,100 (<--wrong!) > User1,20 > User1,50 > User3,100 > > Do I have to create objects? You have to use an expression to cast the second field to an int. Ideally you should import the file as a CSV file and then sort by properties. To import it as a CSV file you will have to add a header line to your file, e.g: User,Size User1,50 User3,100 User1,20 User1,100 Then you can do this: PS> $users = import-csv temp.csv PS> $users | sort user,{[int]$_.size} User Size ---- ---- User1 20 User1 50 User1 100 User3 100 If you cannot (or don't want to) add a header line to your file, you can still split and cast as part of the sort like this: gc temp.csv | sort {$_.split(',')[0]},{[int]$_.split(',')[1]} User1,20 User1,50 User1,100 User3,100 Hope that helps. Jacques |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Sorting | Vista mail | |||
| RE: Sorting XML | PowerShell | |||
| Sorting in Vista | Vista file management | |||
| Sorting | Live Mail | |||
| Sorting contacts | Vista mail | |||