I have two text files, one named “master.txt” and other “slave.txt”. Each text files contains a set of users as below, and I wanted to compare master.txt file with slave.txt file and report the missing ones in the slave.txt file. In the current result, it seems both the files are compared and responds back missing ones across both the files. Could someone help me please?
~]# cat master.txt
user1
user2
user3
~]# cat slave.txt
user2
user4
Script:
$mfile = Get-Content "C:\master.txt"
$sfile = Get-Content "C:\slave.txt"
foreach ($mobj in $mfile) {
foreach($sobj in $sfile){
if ($mobj -ne $sobj) {
Write-Output "$mobj is Not Found:"
}
}
}
Current result:
user1 is Not Found:
user1 is Not Found:
user2 is Not Found:
user3 is Not Found:
user3 is Not Found:
Expected result (these are the ones present in master.txt but not in slave.txt):
user1 is Not Found:
user3 is Not Found: