Last active
May 17, 2018 13:17
-
-
Save jschpp/004e40d1821b3de15f09016aaee0e2d6 to your computer and use it in GitHub Desktop.
Quick and dirty diff in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[switch]$CompareObjects, | |
$left, # if I specify [string[]]$left the Property ReadCount which is created by gc is lost -.-' | |
$right, | |
[switch]$DisplayWhitespace | |
) | |
if (!$CompareObjects) { | |
$left = Get-Content $left | |
$right = Get-Content $right | |
} | |
if ($DisplayWhitespace) { | |
$White = [char]0x00B7 | |
} else { | |
$White = " " | |
} | |
Compare-Object $left $right -CaseSensitive | Sort { $_.InputObject.ReadCount } |` | |
Group-Object {$_.InputObject.ReadCount} |` | |
Select-Object @{Name="Line";Expression={$_.Name}},` | |
@{Name="Left";Expression={$_.Group[0].InputObject -replace " ", $White}},` | |
@{Name="Right";Expression={$_.Group[1].InputObject -replace " ", $White}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ MyDiff -left $a -right $b -CompareObjects -DisplayWhitespace | |
Line Left Right | |
---- ---- ----- | |
51 ····EXIT·1 ····exit·1 | |
54 ····EXIT·0 ····exit·0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment