I am comparing two text files and sending the difference to an output file. Here is my simple code.
$file1 = (Get-Content .\txt1.txt)
$file2 = (Get-Content .\txt2.txt)
compare-object $file1 $file2 | out-file txt3.txt
(Get-Content -Path .\txt3.txt) |
ForEach-Object {
$_ -Replace '=>', 'After'`
-Replace '<=', 'Before'`
} |
Set-Content -Path .\txt3.txt
Get-Content -Path .\txt3.txt
Now here is the output.
InputObject SideIndicator
----------- -------------
banaple After
cherry After
orange Before
strawberry Before
Is it possible to alternate After and Before so that it would be easier for the user to understand this result? My main concern is if I have difference for a lot of lines and they are displayed like this, all After's on top followed by their corresponding Before's underneath, then it might cause confusion to the user. Or if I can put numbers beside them to point which After and Before are partners.
I hope someone could help me out with this. I'm just starting to familiarize myself with the Compare-Object command but I'm really having a hard time getting the modifications I need. I thank in advance whoever will have the answer for my question :)