Jump to content
Sign in to follow this  
kwyking

Finding duplicates lines in text files - Vbs script to Autioit

Recommended Posts

kwyking

Hi forum,

Can someone help me convert this vbs script so that i can include it in my autoit script. I don't want to run it as a seperate script if i can help it.

'# "Search for duplicate lines"'# www.petri.co.il/forums/showthread.php?t=32793'# author: Remco Simons [NL] 2009Const ForReading = 1Const dictKey   = 1Const dictItem   = 2' Search for duplicate lines in:TXTFile = "c:test.txt"Set objDictionary1 = CreateObject("Scripting.Dictionary")objDictionary1.CompareMode = vbTextCompareSet objDictionary2 = CreateObject("Scripting.Dictionary")objDictionary2.CompareMode = vbTextCompareSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile(TXTFile, ForReading)iCnt = 0Do Until objFile.AtEndOfStream  strName = objFile.ReadLine  If Not strName = "" Then       iCnt = iCnt + 1     If (objDictionary1.Exists(strName) = False) Then       objDictionary1.Add strName, iCnt     Else       foundfirst = objDictionary1.Item(strName)       foundfirst = Right("0000"&CStr(foundfirst),4) _          & " - - - - - - - - - - - - - - - - - - -"         If (objDictionary2.Exists(foundfirst) = False) Then            objDictionary2.Add foundfirst, UCase(strName)        End If          objDictionary2.Add Right("0000"&CStr(iCnt),4), strName       End If   End IfLoopobjFile.CloseobjDictionary1.RemoveAllSortDictionary objDictionary2, dictItem, dictKeyDim arrOut()Z = objDictionary2.Count: If Z > 0 Then  ' create an 2D-array to store dictionary information  ReDim arrOut(Z,2)  X = 0  ' populate the string array  For Each objKey In objDictionary2   arrOut(X,dictKey)  = CStr(objKey)   arrOut(X,dictItem) = CStr(objDictionary2(objKey))   X = X + 1  Next  wscript.echo Join2D(arrOut, vbNewLine)Else  wscript.echo "No duplicate entries found"End IfobjDictionary2.RemoveAllwscript.quitFunction SortDictionary(objDict, intSortA, intSortB)  ' http://support.microsoft.com/kb/246067  ' declare our variables  Dim strDict()  Dim objKey  Dim strKey,strItem  Dim X,Y,Z  ' get the dictionary count  Z = objDict.Count  ' we need more than one item to warrant sorting  If Z > 1 Then   ' create an array to store dictionary information   ReDim strDict(Z,2)  X = 0   ' populate the string array For Each objKey In objDict      strDict(X,dictKey)  = CStr(objKey)      strDict(X,dictItem) = CStr(objDict(objKey))     X = X + 1   Next    ' perform a a shell sort of the string array    For X = 0 to (Z - 2)      For Y = X to (Z - 1)      If StrComp((strDict(X,intSortA) & strDict(X,intSortB)), _        (strDict(Y,intSortA) & strDict(Y,intSortB)), _      vbTextCompare) > 0 Then            strKey  = strDict(X,dictKey)            strItem = strDict(X,dictItem)           strDict(X,dictKey)  = strDict(Y,dictKey)            strDict(X,dictItem) = strDict(Y,dictItem)           strDict(Y,dictKey)  = strKey            strDict(Y,dictItem) = strItem       End If    Next  Next    ' erase the contents of the dictionary object   objDict.RemoveAll   ' repopulate the dictionary with the sorted information For X = 0 to (Z - 1)      objDict.Add strDict(X,dictKey), strDict(X,dictItem)   Next  End IfEnd FunctionFunction Join2D(varData, strDelim)   Dim strOutpu   For i = LBound(varData, 1) to UBound(varData, 1)      For j = LBound(varData, 2) to UBound(varData, 2)       If Len(strOutput) > 0 _           Then strOutput = stroutput & strDelim         strOutput = stroutput & varData(i, j)    Next   Next   Join2D = strOutputEnd Function

duplicates.zip

Edited by kwyking

Share this post


Link to post
Share on other sites
Spiff59

There are some recent modified _ArrayUnique functions using Scripting.Dictionary in the Example Script forum that would get you on the right path. Try a search on that function name...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×