Hey PowerShell Guy !, How Can I Remove Duplicate Values From a Pair of Text Files?
Again a Hey Scripting Guy ! translation about replacements in Text files : How Can I Remove Duplicate Values From a Pair of Text Files?
To replace the 35 lines Vbscript solution with 3 loops given in the original article, the following PowerShell commands can be given interactivly on the console or used in a script :
$file1 = get-content c:\scripts\file1.txt
$file2 = gc c:\scripts\file2.txt
set-content c:\scripts\file1.txt ($file1 | where {$file2 -notContains $_})
sc c:\scripts\file2.txt ($file1 |? {$file2 -notContains $_})
as we have seen also in last post : Hey PowerShell Guy !, How Can I Replace Text That Includes Double Quote Marks and a Tab Character? we first read the text into variables change it and write it back.( and as always in the Hey PowerShell Guy series, for more information see the original Hey Scripting guy ! article )
The first 2 lines read the test from the 2 files into variables where the second line does use aliases.
in the next 2 lines we remove filter out the numbers both variables do contain and write them back to the files again the fourth line is the same as the third only using aliases for the commands (Ok, I smugle a bit here as Where is also an alias for Where-Object ;-) ).
You can see again a lot easier to read and understand as the VbScript example
(and .. uhh,. did I allready mention that it is a little bit shorter ? )
Enjoy,
Greetings /\/\o\/\/