looking for a script that will compare 2 text files and remove duplicates

I am looking for a scipt that will take a list of servers (list1.txt) and compare it to a second list (list2.txt) if a server is in list 1 I want it deleted from the output so basicily if something is in BOTH lists then i want it not in the out put
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Do you want:

1) In List1 but not List2
2) In List2 but not List1
3) (In List1 but not List2) And (In List2 but not List1)

NAMEWITHELD12Author Commented:
1) no
2) yes
3) none of that

and if it is in both list i dont want it
thanks I appreciate the help , I am learning this kinda thing right now and could use the help!!!
Patrick MatthewsCommented:
OK, this is VBScript.

Dim fso, tsIn, tsOut, dic, entry

Set fso = CreateObject("Scripting.FileSystemObject")
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1

Set tsIn = fso.OpenTextFile("c:\folder\subfolder\List1.txt")

Do Until tsIn.AtEndOfStream
    entry = tsIn.ReadLine
    If Not dic.Exists(entry) Then dic.Add entry, entry

Set tsIn = fso.OpenTextFile("c:\folder\subfolder\List1.txt")
Set tsOut = fso.CreateTextFile("c:\folder\subfolder\Results.txt", True)

Do Until tsIn.AtEndOfStream
    entry = tsIn.ReadLine
    If Not dic.Exists(entry) Then tsOut.WriteLine entry

Set tsIn = Nothing
Set tsOut = Nothing
Set fso = Nothing
Set dic = Nothing

MsgBox "Done"

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Herels a batch file version

@echo off

del "list.tmp" 2>nul

for /f "tokens=* usebackq" %%a in ("list1.txt") do (
   findstr "\<%%a\>" "list2.txt" >nul
   if errorlevel 1 echo %%a>>"list.tmp"

move "list.tmp" "list1.txt"

NOTE: Depending on the contents of your lists, you might be able to get away with using just "%%a" instead of "\<%%a\>" in which case, you can also use FIND instead of FINDSTR.

NOTE: Also, if there are no spaces in your filenames then you could use:

@echo off

del list.tmp 2>nul

for /f "tokens=*" %%a in (list1.txt) do (
   find "%%a" list2.txt >nul
   if errorlevel 1 echo %%a>>list.tmp

move list.tmp list1.txt

NOTE: I also changed FINDSTR to FIND etc,,
NAMEWITHELD12Author Commented:
AWESOME thanks , i am looking at each part of the script to understand what each line does , thanks again
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.