Friday, May 31, 2019

Powershell: Compare-Object to analyze two files

Displaying differences between two files like Linux 'diff' command, you can use Powershell Compare-Object cmdlet.

# You do not find any identical differences with just giving file names.
PS > Compare-Object .\sample01.txt .\sample02.txt

InputObject SideIndicator
----------- -------------
.\sample02.txt =>
.\sample01.txt <=


# You can identify differences between two files with following method.
PS > Compare-Object (Get-Content .\sample01.txt) (Get-Content .\sample02.txt)

InputObject SideIndicator
----------- -------------
efg =>
hijkl =>
efgh <=
ijkl <=

No comments:

Post a Comment