![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Comparing files with compare-object I've done everything I can think of to properly format a string to compare between 2 files. I've confirmed to my best of knowledge that one particular entry is *exactly* the same in two files (same lenght, etc). However, I cannot seem to get compare-object to find a match. 76# import-csv file1.csv|%{$_.'SN,CN'}|%{$_.replace(' (+)','')}|%{if($_ -match "some_user_removed"){$_}}|%{$_.length} 24 24 24 24 24 24 24 24 24 24 24 77# get-content file2.txt|%{$_.substring(13,56)}|%{$_.trimend()}|%{if($_ -match "some_user_removed"){$_}}|%{$_.length} 24 So above, I've confirmed (I think) that the string is exactly the same lenght, however I can't get compare-object to indicate a match. One file has 9,000 entries (lines), and the other has over 63,000. I'm trying to get *only* the entries that match exactly between each file. Something like this: 79# compare-object -ReferenceObject $(gc 1.txt) -DifferenceObject $(gc 2.txt) -includeequal -excludedifferent InputObject SideIndicator ----------- ------------- test == 80# gc 1.txt test testing 81# gc 2.txt test Any ideas? Gotchas I might be missing? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Comparing files with compare-object More info... If I try to do an exact match for the -referenceobject and -differenceobject, I can get a match. This works: 85# compare-object -referenceobject $(get-content 1.txt|%{$_.substring(13,56)}|%{$_.trimend()}|%{if($_ -mat ch "some_user_removed"){$_}}) -differenceobject $(import-csv 2.csv|%{$_.'SN,CN'}|%{$_.replace(' (+)','')}|% {if($_ -match "some_user_removed"){$_}}) -includeequal -excludedifferent InputObject SideIndicator ----------- ------------- some_user_removed == But again, this doesn't: 86# compare-object -referenceobject $(get-content 1.txt|%{$_.substring(13,56)}|%{$_.trimend()}) -difference object $(import-csv 2.csv|%{$_.'SN,CN'}|%{$_.replace(' (+)','')}) -includeequal -excludedifferent 87# My understanding is compare-object is not supposed to be a match line X in file A with match line X in file B. In other words, line X in file A can still be found to be a match with line Y in file B as long as the content/string is the same. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Comparing files with compare-object > Any ideas? Gotchas I might be missing? I've found a workaround. It ain't pretty, but seems to work... |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Comparing files with compare-object "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message news:OjyUUr8vHHA.1756@TK2MSFTNGP05.phx.gbl... > I've done everything I can think of to properly format a string to compare > between 2 files. > Did you try setting the -SyncWindow to something larger like 100? -- Keith |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Comparing files with compare-object Keith Hill wrote: > "Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message > news:OjyUUr8vHHA.1756@TK2MSFTNGP05.phx.gbl... >> I've done everything I can think of to properly format a string to >> compare between 2 files. >> > > Did you try setting the -SyncWindow to something larger like 100? > > -- > Keith No I didn't! That has to be the key... I'm comparing a 8,000 line file to a 63,000 one... |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: ignore whitespace when comparing files using compare-object? | PowerShell | |||
| ignore whitespace when comparing files using compare-object? | PowerShell | |||
| Re: ignore whitespace when comparing files using compare-object? | PowerShell | |||
| Testing object arrays using Compare-Object and -contains | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||