I'm losing my mind trying to recreate the output of the following Linux command in a Windows Environment:
diff --old-line-format='%L' --new-line-format='' --unchanged-line-format='' file1 file2 | grep -v '^$'
I can't install anything, not even Notepad++ plugins, since it's a corporate server. All I got to work with is CMD or PowerShell (as far as I can think of)
Closest I've gotten is the following Powershell 'script':
$file1 = Get-Content "file1.txt"
$file2 = Get-Content "file2.txt"
$only_in_file1 = $file1 | Where-Object {
$_ -notin $file2
}
$only_in_file1
But it fails to show the exact same output I'd get in Linux. Let me explain,
file1:
#AK.70.1.1.5
ServerTokens Prod
Header always unset "X-Powered-By"
Header unset "X-Powered-By"
#AK.70.1.1.6
ServerSignature Off
AddServerHeader Off
#ServerTokens Prod
#ServerSignature Off
#AddServerHeader Off
file2:
blah blah blah
durr durr durr
ServerTokens Prod
blah blah blah
durr durr durr
ServerSignature Off
AddServerHeader Off
Expected output (what I'd get in Linux):
#AK.70.1.1.5
ServerTokens Prod
Header always unset "X-Powered-By"
Header unset "X-Powered-By"
#AK.70.1.1.6
ServerSignature Off
AddServerHeader Off
#ServerTokens Prod
#ServerSignature Off
#AddServerHeader Off
Actual output (what I get from PowerShell)
#AK.70.1.1.5
Header always unset "X-Powered-By"
Header unset "X-Powered-By"
#AK.70.1.1.6
#ServerTokens Prod
#ServerSignature Off
#AddServerHeader Off
You see, although I commented file2 lines in file1, and pasted them on a different place, it stills considers them as if they weren't different.
I really cant Wrap my head around this topic. It's been like 4 hours now. Not kidding.
Any idea is welcome!
Get-Contentreads multiple (or all) lines as one item. What returns:$file1.Countin either case?