Sign in to follow this  
Followers 0
t0ddie

remove duplicates from a file

8 posts in this topic

#1 ·  Posted (edited)

this isnt working...

i want to remove all duplicate entries,

a lil help?

here is test.txt

1111
2222
1111
2222
1111
2222
1111
2222

here is the script. im sure its just ONE LITLE THING i overlooked

Dim $a_text = ""
$sFile = FileOpen(@ScriptDir & "\test.txt",0)
    SplashTextOn("checking...","Removing Duplicates. please wait.",200,60,420,320)
    sleep(1000)
    $whatthefuck = 0
            While 1
                $whatthefuck = $whatthefuck + 1
                $found = 0
                $line = FileReadLine($sFile, $whatthefuck)
                If @error = -1 Then ExitLoop

                If IsArray($a_text) Then
                    For $i = 0 To UBound($a_text) - 1
                        If ($a_text[$i] == $line) Then;==?
                            $found = 1
                            ExitLoop
                        EndIf
                    Next
                EndIf
                If (Not $found) Then
                    If IsArray($a_text) Then
                        ReDim $a_text[UBound($a_text) + 1]
                    Else
                        Dim $a_text[1]
                    EndIf
                    $a_text[UBound($a_text) - 1] = $line
                EndIf
            WEnd
            SplashOff()
            FileClose($sFile)
            MsgBox(0,"test","output saved in test.txt")

this should leave me with

1111
2222

but it does not. please help?

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites



which portion of the code save your result back to the file ?

heh.. i knew it was something small i overlooked.

but i cant get it working.

i added this, and it seems to do nothing

FileClose($sFile)
            FileDelete($sFile)
$sFile = FileOpen(@ScriptDir & "\test.txt",1)
            FileWrite($sFile,$a_text)
            FileClose($sFile)

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

heh.. i knew it was something small i overlooked.

but i cant get it working.

i added this, and it seems to do nothing

FileClose($sFile)
            FileDelete($sFile)
$sFile = FileOpen(@ScriptDir & "\test.txt",1)
            FileWrite($sFile,$a_text)
            FileClose($sFile)
Correct... You do not set $a_text anywhere...

$A_text is an Array...

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Correct... You do not set $a_text anywhere...

$A_text is an Array...

first line in the script

Dim $a_text = ""

i also see redim in places in the code.. so it should be setting the array

i just copied and pasted this code from my other script where it runs fine.

i dont know why it wont run the same way here...

its the exact same code.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

first line in the script

Dim $a_text = ""

i also see redim in places in the code.. so it should be setting the array

i just copied and pasted this code from my other script where it runs fine.

i dont know why it wont run the same way here...

its the exact same code.

Think you need to do some more reading...

$a_text is something totally different than $a_text[0]

Do NOT expect $a_text to contain all array values as one big string with @CRLF's .....

YOu will have to loop through the array and write each instance separately to the file ...

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

how does this look?

it works...

Dim $a_text = ""
$sFile = FileOpen(@ScriptDir & "\test.txt",0)
$fuckFile = FileOpen(@ScriptDir & "\test2.txt",1)
    SplashTextOn("checking...","Removing Duplicate keys. please wait.",200,60,420,320)
    sleep(1000)
    $whatthefuck = 0
            While 1
                $whatthefuck = $whatthefuck + 1
                $found = 0
                $line = FileReadLine($sFile, $whatthefuck)
                If @error = -1 Then ExitLoop

                If IsArray($a_text) Then
                    For $i = 0 To UBound($a_text) - 1
                        If ($a_text[$i] == $line) Then;==?
                            $found = 1
                            ExitLoop
                        EndIf
                    Next
                EndIf
                If (Not $found) Then
                    If IsArray($a_text) Then
                        ReDim $a_text[UBound($a_text) + 1]
                    Else
                        Dim $a_text[1]
                    EndIf
                    $a_text[UBound($a_text) - 1] = $line
                    FileWrite($fuckFile,$line & @CRLF)
                EndIf
    
            WEnd
            SplashOff()
            FileClose($sFile)
FileClose($fuckFile)

thanks for your comments


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

how does this look?

it works...

-snip-

thanks for your comments

Other than the childish variable names and the strange indentation of your code you seem to like, there's nothing wrong with the logic at first glace ...


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  
Followers 0