![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Re: compare-object does not sort on sideindicator To sort on two, or more, properties and see the next sort, there must be repeated values from the previous property. Your code should work fine, but could be simplified since Sort-Object sorts in Ascending order by default, which is equivalent as the attribute 'Descending=$false'. sc fileA.txt (gps | % {$_.name} | sort) sc fileB.txt (gps | % {$_.name} | sort -des) # the syncWindow used here is not optimun for accurate results, # this way there will be repeated instances $testobject = diff (gc fileA.txt) (gc fileB.txt) -s 30 # this is equivalent to your sort statement, inputObject # in ascending and sideIndicator in descending $testobject | sort inputobject, @{e = {$_.sideIndicator}; d = $true} # this sorts both properties in ascending order $testobject | sort inputobject, sideindicator ##################################################################### # output from first sort, note that '=>' is before '<=' for # each inputObject value InputObject SideIndicator ----------- ------------- AluSchedulerSvc => AluSchedulerSvc <= audiodg => audiodg <= AutoLaunchWLASU => AutoLaunchWLASU <= . . . # output from second sort, here '<=' is before '=>' for each # inputObject value InputObject SideIndicator ----------- ------------- AluSchedulerSvc <= AluSchedulerSvc => audiodg <= audiodg => AutoLaunchWLASU <= AutoLaunchWLASU => . . . -- Kiron |
My System Specs![]() |
| | #2 (permalink) |
| | Re: compare-object does not sort on sideindicator |
My System Specs![]() |
| | #3 (permalink) |
| | Re: compare-object does not sort on sideindicator Hi Tao Ma, No mistake, Compare-Object compares one set against the other, if no match is found it 're-syncs' the order of one set and compares again. By default the -SyncWindow is set to 5. Since files 1.txt and 2.txt contain 3 lines each, below the SyncWindow, it matches all lines and nothing outputs. If you modify 2.txt content to: 1 2 2 3 Compare-Object finds the extra line. PS: Your English is great! -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| compare-object | PowerShell | |||
| compare object | PowerShell | |||
| Compare-Object and Get the name of object/File? | PowerShell | |||
| Testing object arrays using Compare-Object and -contains | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||