Sign in to follow this  
Followers 0
xdp22

2 files delete this same lines

11 posts in this topic

Hello i have one ask, is this possible to :

When i got 2 files - file1.txt and file2.txt

This files got many lines, example :

file1.txt

login1
login2
login3
login4

file2.txt

login5
login6
login1
login2

See that? in file1 and file2 was line login1 and login2

It's possible to make script what read two txt files, and if txt file has the same line, delete it from ONE txt file?

Thanks sorry for bad englisch

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

xdp22,

Hello again! ;)

I would suggest using _FileReadToArray to get the 2 files into 2 arrays. Then moving through each array in turn, delete any double entries.

See what you can come up with - I will have a go myself and we will see which you prefer. :)

M23

Edit:

Her is my version if you get stuck:

#include <File.au3>
#include <Array.au3>

Global $aArray1, $aArray2

_FileReadToArray("File1.txt", $aArray1)
_FileReadToArray("File2.txt", $aArray2)

_ArrayDisplay($aArray1)
_ArrayDisplay($aArray2)

; Look at each element of array 1 in turn
For $i = 1 To $aArray1[0]
    ; Work through the second array backwards or the indexing will error
    For $j = $aArray2[0] To 1 Step -1
        ; And see if the same element exists in array 2
        If $aArray2[$j] = $aArray1[$i] Then
            ; If it does, delete it and reduce the count
            _ArrayDelete($aArray2, $j)
            $aArray2[0] -= 1
        EndIf
    Next
Next

_ArrayDisplay($aArray1)
_ArrayDisplay($aArray2)

; Finally, use _FileWriteFromArray to rewrite the files, but be careful about the [0] count element

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Have a look below at post #8

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks for both users, but i need have it "automatic" cuz in this text files is near 60 000 lines ;)

Share this post


Link to post
Share on other sites

Thanks for both users, but i need have it "automatic" cuz in this text files is near 60 000 lines ;)

What do you mean with automatic? Do you want to monitor the files all the time and correct them constantly? Do you mean writing back to the files automatically?

You'll have to put some effort in yourself. The provided examples are already almost fully functional.

If you get stuck modifying them to your needs you'll have to explain how you are trying to modify them, and what you have tried that doesn't work.

Share this post


Link to post
Share on other sites

Here my version:

That version does have a problem in that given this input:

Local $a1[5] = ["login2", "login12", "login3", "login4", "login7"]
Local $a2[5] = ["login5", "login6", "login1", "login2", "login8"]

The "login1" entry will cause the "login12" entry to be removed.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Code removed. See post #9

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Good catch Spiff59!

This should also work if I'm not missed something again ;) :

#include <Array.au3>
Local $a1[6] = ["login2", "login12", "login3", "login4", "login7", "login11"]
Local $a2[6] = ["login1", "login2", "login5", "login6", "login8", "login100"]

;~ Local $a1, $a2
;~ _FileReadToArray("File1.txt", $a1)
;~ _FileReadToArray("File2.txt", $a2)


$aString = _ArrayToString($a1) & "|"
$i = 0
While 1
    $search = StringRegExpReplace($aString, "(?i)(" & $a2[$i] & "\|)", "")
    If @extended Then
    _ArrayDelete($a2, $i)
    $i -= 1
    EndIf
    $i += 1
    If $i = UBound($a2) Then ExitLoop
WEnd

_ArrayDisplay($a2)
;~ _FileWriteFromArray("File2.txt", $a2)

Please test again.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Guys,

The OP has admitted in an unsolicited PM that he is trying to spam a Polish website (trying 60000 accounts and passwords) with the script of which this is part. I have replied stating that I am no longer helping in this or any other his threads which appear to have a connection. ;)

Thought I would pass on the info - up to you to decide your personal course of action. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I agree M23, this is really bullshit to utilize our help for any criminal activities! ;)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

He is now blocked on my system and I've removed my code. Thanks Big M.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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