Skip to content

Instantly share code, notes, and snippets.

@jschpp
Last active May 17, 2018 13:17
Show Gist options
  • Save jschpp/004e40d1821b3de15f09016aaee0e2d6 to your computer and use it in GitHub Desktop.
Save jschpp/004e40d1821b3de15f09016aaee0e2d6 to your computer and use it in GitHub Desktop.
Quick and dirty diff in powershell
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}}
λ 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