I have a text file containing a single column of IMEIs (file1.txt). I have a second file containing a single column of IMEIs (file2.txt).
What I'm trying to do is take each IMEI in file2.txt and search through file1.txt locating any matches and then when it finds a match, remove that line in file1.txt.
What's making it difficult is the multiple searches I need to perform at once. Doing each one at a time would take quite a while as there are hundreds of IMEIs in each file.
Does anyone have any suggestions to accomplish this task?
Script:
$orders = Get-Content c:\file2.txt
foreach ($order in $orders) {
Get-Content file1.txt | Select-String -Pattern "$order" -NotMatch
}
The above works but because I'm searching a couple hundred "matches", it returns the "not matches" every time so it's returning thousands of results.
You can use a
compare-object
here.That will remove what is equal and only give back what is in the first file, removing all like IMEI's. You can then just export it with
Out-File
and overwrite your previous file.