Should I give up on Compare-Object or am I overlooking something?
- Larry
larry;
Try this:
$dif = Compare-Object -ReferenceObject $(Get-Content test.txt) -DifferenceObject
$(Get-Content test2.txt) -IncludeEqual
$lineNumber = 1
foreach ($difference in $dif)
{
if ($difference.SideIndicator -ne "==")
{
Write-Output "Line Number $linenumber is different"
}
else
{
Write-Output "Line Number $linenumber is equal"
}
$lineNumber ++
}
Karl
http://unlockpowershell.wordpress.com/
You may have more patience than me but I gave up using this cmdlet on text
files long ago.
As to what to use Findstr, WinDiff come to mind both from Microsoft and Diff
(you should be able to find a BSD version).
"Larry__Weiss" wrote:
> .
>
- Larry
Larry;
I use WinMerge -> http://winmerge.org/
WinMerge has the ability to bew scripted:
http://winmerge.org/docs/manual/Version_control.html#d0e9121
http://winmerge.org/docs/manual/Command_line.html
Karl
Karl
http://unlockpowershell.wordpress.com/
Here's a simple example:
PS>"alpha","bravo","charlie" | set-content ABC.txt
PS>"charlie","delta","echo" | set-content CDE.txt
PS>$abc = gc .\ABC.txt | %{$i = 1} { new-object psobject -prop
@{LineNum=$i;Text=$_}; $i++}
PS>$cde = gc .\CDE.txt | %{$i = 1} { new-object psobject -prop
@{LineNum=$i;Text=$_}; $i++}
PS>Compare-Object $abc $cde -Property Text -PassThru -IncludeEqual
Text LineNum SideIndicator
---- ------- -------------
charlie 3 ==
delta 2 =>
echo 3 =>
alpha 1 <=
bravo 2 <=
Hope that helps,
-Paul
"Larry__Weiss" wrote:
> .
>
You can do this with compare-object if you use the data from get-content to
create a new custom object with the line number. Here is an example:
> "alpha","bravo","charlie" | set-content ABC.txt
> "charlie","delta","echo" | set-content CDE.txt
> $abc = gc .\ABC.txt | %{$i = 1} { new-object psobject -prop @{LineNum=$i;Text=$_}; $i++}
> $cde = gc .\CDE.txt | %{$i = 1} { new-object psobject -prop @{LineNum=$i;Text=$_}; $i++}
> Compare-Object $abc $cde -Property Text -PassThru -IncludeEqual
Text LineNum SideIndicator
---- ------- -------------
charlie 3 ==
delta 2 =>
echo 3 =>
alpha 1 <=
bravo 2 <=
Hope that helps,
Paul
"Larry__Weiss" wrote:
> .
>
I forget how much of PowerShell's "power" I leave untouched when I design a
solution.
- Larry