![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | How can you find the lines Compare-Object determines to be differe Regardless of whether Compare-Object is comparing two text files or the "chosen" properites of two collections: Files/Processes/... ; there is a notion of a line or index where the difference was found. Unfortunately I've not been able to find out how to make Compare-Object do this. I thought on a lark I could do pipe the outputs and track the differences myself however the line counts are ALL messed up The below will illustrate what I'm seeing ## file Out1; copy OUt1 to Out2 and change one character clock.avi imsins.BAK Blue Lace 16.bmp Coffee Bean.bmp ## this just dumps out the "line number" and file for debugging purposes Compare-Object ${c ut1} ${c ut2} -includeequal | % {$i = 0} { $i++; echo"`$i is $i and `$_ is $_`n"} What I've found are the lines that are _equal_ are feed to the pipe first. Only after this has been drained are the differences piped out. My guess is Compare-Object is using two arrays (Equal/Diff) and then dumping them to the pipe. So now I'm back to square one. Does someone know whether Compare-Object can dump the "line" numbers out? If not has someone written a Comparsion tool which will dump out what index/line in the Array/file the differences are occuring. Seems like it would have been such a simple feature to add :< |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How can you find the lines Compare-Object determines to be differe Here is a way with Where-Object and the containment operators. Pipe the line numbers to where-object so it filters each different line and outputs its number: 1..${c ut1}.length | ? {${c ut2} -notContains ${c ut1}[$_ - 1]}# ...for the equal lines 1..${c ut1}.length | ? {${c ut2} -contains ${c ut1}[$_ - 1]}-- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How can you find the lines Compare-Object determines to be differe "Kiron" <Kiron@xxxxxx> wrote in message news:82172493-D903-40C0-853C-D9A41A0912E3@xxxxxx Quote: > Here is a way with Where-Object and the containment operators. Pipe the > line numbers to where-object > so it filters each different line and outputs its number: > > 1..${c ut1}.length | ? {${c ut2} -notContains ${c ut1}[$_ - 1]}> > # ...for the equal lines > 1..${c ut1}.length | ? {${c ut2} -contains ${c ut1}[$_ - 1]}a script I posted about a week ago that does exactly what you want: http://janel.spaces.live.com/blog/cn...88C2!345.entry The blog is in French but you should be able to copy/paste the script (compare-textfile.ps1) and use it straight away. Let me know however if you have any question. The script was not tested thoroughly and is provided "as is" with no guarantee of any sort. Jacques |
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 | |||