File Manipulation mit Array und Regex: Nur numerische Zeilen in File löschen -HILFE-

  • so?

    [autoit]

    $text="1.2.3.4 bla blub 128.2.3.4 huhu 17.12.2012 tralala 192.168.2.1 AutoIt"
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $text = ' & $text & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    [/autoit][autoit][/autoit][autoit]

    $ret= StringRegExpReplace($text,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}","")
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ret = ' & $ret & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    [/autoit]
  • Danke!

    Habe so das Textfile geladen:
    $text = @ScriptDir & "test_offline.log"

    immer noch im textfile:
    101.255.12.26
    101.44.1.106
    101.44.1.107
    101.44.1.108
    101.44.1.109
    101.50.17.14
    .....

    "Thinking in binary"

  • Andy Deines klappt. Aber nicht wenn ich ein Textfile benutze. Da muss doch dann noch Readline irgendwo hin und falls es eine IP Adresse ist muss die Zeile gelöscht werden?

    "Thinking in binary"

  • [autoit]

    $text="1.2.3.4/bla/blub 1234567890 " & @crlf & "http.//bla.blub/tralala" & @crlf & "128.2.3.4/huhu " & @crlf & "17.12.2012 tralala " & @crlf& "http://192.168.2.1/AutoIt" &@crlf

    [/autoit][autoit][/autoit][autoit]

    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $text = ' & $text & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    [/autoit][autoit][/autoit][autoit]

    filedelete("IP.txt")
    filewrite("IP.txt",$text)

    [/autoit][autoit][/autoit][autoit]

    $dat=fileread("IP.txt")

    [/autoit][autoit][/autoit][autoit]

    $ret= StringRegExpReplace($dat,"(?miU)(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.*\r\n)","")
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ret = ' & $ret & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

    [/autoit][autoit][/autoit][autoit][/autoit]

    weil Weihnachten ist, legen wir heute mal den Arm aus der Sonne^^


    //EDIT
    schau mal, was bei deinem $text = @ScriptDir & "test_offline.log" in der Variablen steht!!!

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    4 Mal editiert, zuletzt von Andy (26. Dezember 2014 um 21:57)

  • Andy ich habe ein Textfile das reingeladen werden muss und danach kommt dein Code.
    Jede Zeile im Textfile muss gecheckt werden ob IP oder Domainname...

    Happy New Year!

    So wird in IP.txt die Variable von $Text reingeschrieben (also: test_offline.log)

    "Thinking in binary"

    • Offizieller Beitrag

    $text = @ScriptDir & "test_offline.log"


    Mach doch mal, was dir gesagt wird!! Gib nach dieser Zuweisung den Inhalt von $text in die Konsole aus. Dann wirst du sehen, dass das totaler Quark ist, weil etwas Wesentliches drin fehlt (die Hilfe sagt dir auch was).

  • Regex upgedatet....in Post #5

  • BugFix: Ich habe genau das getan was Du und Andy mir vorgaben. Ich benötige in einem Textfile Domains und die IPs müssen raus. Wäre schön es mir nach ein paar Stunden einfacher zu machen.


    Es funktioniert jetzt aber nicht ganz:
    Das speichert er in IP.txt
    feed:http://www.ddday.com/feed/

    Das lässt er in der alten Textdatei
    http://<%= blog.tumblr_url %>

    "Thinking in binary"

    Einmal editiert, zuletzt von R4z0r (26. Dezember 2014 um 23:01)

    • Offizieller Beitrag

    Mach mal eben ist nicht. Zeig dein Script, so wie du es jetzt hast und hänge mal eine Beispiel Text.txt an.
    Keine Sau weis was du versucht hast.

  • OK hier ist das Script das zum grössten Teil sowieso von Andy ist: :D

    Also diesen Code benutzen und dann ein Textfile im gleichen Verzeichnis eerstellen mit diesem Inhalt:

    --- CONTENTS VON test_offline.log ---
    feed:http://www.ddday.com/feed/
    http://<%= blog.tumblr_url %>
    http://1.227.196.123:8080
    http://101.255.12.26:9292
    http://101.44.1.106:80
    http://101.44.1.107:80
    http://101.44.1.108:80
    http://101.44.1.109:80
    ; ...und so weiter...

    Wenn Ihr dann das Script mit dem Textfile laufen lasst bekommt Ihr:

    IP.txt

    mit diesem Inhalt:
    feed:http://www.ddday.com/feed/

    und das wars dann schon. IP.txt hätte auch die 2. Zeile vom Textfile integrieren müssen da dies ebenso NICHT eine IP Adresse ist.

    Bitte um Hilfe.

    P.S. Beim RegEx habe ich meines anstatt Andys benutzt.

    "Thinking in binary"

    • Offizieller Beitrag

    Meinst du sowas?

    [autoit]

    #include <File.au3>

    [/autoit][autoit][/autoit][autoit]

    Local $aRecords
    If Not _FileReadToArray(@ScriptDir & "\test_offline.log", $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array error:" & @error)
    Exit
    EndIf
    FileDelete(@ScriptDir & "\IP.txt")
    For $x = 1 To $aRecords[0]
    $ret = StringRegExp($aRecords[$x], "(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,4})", 0)
    If Not $ret Then
    FileWriteLine(@ScriptDir & "\IP.txt", $aRecords[$x])
    EndIf
    Next

    [/autoit]

    Edit: Noch mal anders

    [autoit]

    #include <File.au3>
    $dat=FileRead(@ScriptDir & "\test_offline.log")
    FileDelete(@ScriptDir & "\ip.txt")
    $ret = StringRegExpReplace($dat, "(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,4}\r\n)", "")
    FileWrite(@ScriptDir & "\ip.txt",$ret)

    [/autoit]


    Das RegExp Pattern ist auf deine Beispieldaten aufgebaut, also mit Port.
    Wenn die Datei auch Ip ohne Port enthält, muss das Pattern geändert werden.

  • Sieht Super aus. Hast Du eine Idee wie man kurz noch einfügen kann das eine Textdatei bleibt die NICHT die IP übrig hat? Ich sehe nur Textfiles die diese IPs drin haben.


    Schade - Dein nmal anders Edit (wenig code) ergibt dann diese Textdatei (Inhalt - sieht nach RegEx Problemen aus):

    Code
    feed:http://www.ddday.com/feed/
    http://<%= blog.tumblr_url %>
    http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://107.2.141.6:36081
    http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://125.163.177.13:31281
    http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://173.216.197.60:36081
    http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://174.50.132.155:36081
    http://174.50.3.155:36081
    http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://184.190.209.150:36081
    http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://http://

    Problem liegt anscheinend darin wenn eine IP Adresse einen Port mit 5 Digits hat und http:// wird nicht gelöscht. Was auch fehlt ist eine Zeile pro IP/Domain/Was auch immer

    ---------------------------------
    Dein 1. Code funktioniert! DANKE! :rock::party:

    "Thinking in binary"

    Einmal editiert, zuletzt von R4z0r (27. Dezember 2014 um 01:49)

    • Offizieller Beitrag

    Ich habe jetzt schon mehrfach gesagt, wir brauchen die Textdatei.
    Dein Beispiel entspricht nicht der Form, die deine Textdatei hat.
    Das kann natürlich an dem bescherten WBB Editor liegen.
    Aus dem Grund funzt auch nicht das 2. Beispiel, weil ein Http:// und ein 5 Stelliger Port nicht berücksichtigt wird.
    Problemlösungen sind nur so gut, wie die Beschreibung des Problems. ;)