Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Re: compare-object does not sort on sideindicator

Reply
 
Old 07-01-2008   #1 (permalink)
Kiron


 
 

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 SpecsSystem Spec
Old 07-01-2008   #2 (permalink)
Tao Ma


 
 

Re: compare-object does not sort on sideindicator

My System SpecsSystem Spec
Old 07-01-2008   #3 (permalink)
Kiron


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46