Probleme mit skript, dass txt zerlegt

  • Hallo!

    Ich habe Textdateien die mehrere 1000 Zeilen lang sind und möchte daraus bestimmte Bereiche rauskopieren

    Die txt sieht ungefähr so aus:

    Spoiler anzeigen

    Timestamp Found GazepointX GazepointY

    12 Both 635 435
    32 Both 630 441
    52 Both 612 382
    72 Both 646 438
    92 Both 615 428
    111 Both 618 433
    131 Both 616 403
    151 Both 623 417
    171 Both 634 471
    191 Both 611 412
    211 Both 635 455
    231 Both 630 369
    251 None -1280 -1024
    271 None -1280 -1024


    In der ersten Spalte ist immer ein Zeitstempel, und ich möchte jeweils 20 verschiedene Zeitbereiche rauskopieren. Dazu habe ich ein Skript, dass mal ein Kollege geschrieben hat. Ich möchte daran eine Kleinigkeit verändern, weis aber nicht wie. Mit dem bisherigen Skript sieht es so aus, dass alle Zeitbereiche untereinander in eine neue Textdatei geschrieben werden, da sehe ich aber nicht wann ein Zeitbereich aufhört und der nächste anfängt. Deswegen hätte ich da gerne eine Leerzeile oder irgendwas dazwischen, damit man auf den ersten Blick die einzelnen Bereiche findet.

    Das Skript sieht so aus:

    Spoiler anzeigen
    [autoit]

    Dim $Input_datei ="HT1_1EFD.txt"
    Dim $Output_datei ="HT1_1_cut.txt"
    ;Datei öffnen
    $Input = FileOpen($Input_datei, 0)
    If FileExists($Output_datei) Then FileDelete($Output_datei)
    $Output = FileOpen($Output_datei, 1)
    ; Check if file opened for writing OK
    If $Output = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
    EndIf

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

    ;GUI_EINBINDEN
    #include <GUIConstants.au3>
    GUICreate("Daten filtern", 300, 50, 100, 100)
    $Label_Zaehler=GUICtrlCreateLabel ("", 10, 30, 280, 20)
    GUISetState()

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

    ;Schleife für Logfile einlesen
    Dim $Begin_Zahlenwerte = 0
    Dim $Zaehler = 0
    While 1
    $Zeile = FileReadLine($Input)
    If @error = -1 Then ExitLoop

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

    $Zaehler = $Zaehler +1
    GUICtrlSetData($Label_Zaehler, $Zaehler)

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

    Dim $Ausgeben = 1
    Dim $Zeile_original = $Zeile

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

    if ($Begin_Zahlenwerte == 1) then

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

    ;Zeile zerlegen
    $pos = Stringinstr($Zeile, chr(9))
    $timestamp = int (StringMid ( $Zeile, 1, $pos-1))
    $Zeile = StringMid( $Zeile, $pos+1)

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

    $pos = Stringinstr($Zeile, chr(9))
    $found = StringMid ( $Zeile, 1, $pos-1)
    $Zeile = StringMid( $Zeile, $pos+1)

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

    ; if ($found <> "both") then
    ; $Ausgeben = 0
    ; endif

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

    if ($Ausgeben == 1) then
    Dim $Anfangszeit = 0
    Dim $Endszeit = 0

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

    $Ausgeben = 0
    $Anfangszeit = 80189
    $Endzeit = 114555
    if ( $timestamp >= $Anfangszeit and $timestamp <= $Endzeit) then $Ausgeben = 1
    ; hier soll Leerzeile dazwischen

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

    $Anfangszeit = 164673
    $Endzeit = 199040
    if ( $timestamp >= $Anfangszeit and $timestamp <= $Endzeit) then $Ausgeben = 1

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

    endif
    endif

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

    if ($Zeile == "Timestamp Found GazepointX GazepointY") then
    $Begin_Zahlenwerte = 1
    endif

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

    if ($Ausgeben == 1) then
    FileWriteLine($Output, $Zeile_original)
    endif
    Wend
    GUIDelete()
    msgbox(0,"Fertig","Bin fertig!")
    Exit

    [/autoit]


    Kann mir da jemand nen tipp geben?

    3 Mal editiert, zuletzt von jimmyeatworld (26. Oktober 2008 um 10:27)

  • Das hat leider nicht funktioniert. in der textdatei die rauskommt ist keine leerzeile drin

    Spoiler anzeigen

    114486 Both 882 330
    114506 Both 890 272
    114526 Both 875 292
    114546 Both 901 317 hiernach sollte leerzeile sein
    164686 Both 440 498
    164706 Both 442 422
    164726 Both 454 429

    ich hab auch anstatt @CRLF ausprobiert ob chr(9) funktioniert, aber da wird nur an jede Zeile ein Tabstopp angefügt.


    kann man nicht eine if ... then klausel einbauen, dass wenn sich zwei zeilen um mehr als 100 unterscheiden eine leerzeile geschrieben wird? (leider kann ich es nicht selbst programmieren)

    Einmal editiert, zuletzt von jimmyeatworld (25. Oktober 2008 um 21:59)

  • Spoiler anzeigen
    [autoit]

    Dim $Input_datei = "HT1_1EFD.txt"
    Dim $Output_datei = "HT1_1_cut.txt"
    ;Datei öffnen
    $Input = FileOpen($Input_datei, 0)
    If FileExists($Output_datei) Then FileDelete($Output_datei)
    $Output = FileOpen($Output_datei, 1)
    ; Check if file opened for writing OK
    If $Output = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
    EndIf

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

    ;GUI_EINBINDEN
    #include <GUIConstants.au3>
    GUICreate("Daten filtern", 300, 50, 100, 100)
    $Label_Zaehler = GUICtrlCreateLabel("", 10, 30, 280, 20)
    GUISetState()

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

    ;Schleife für Logfile einlesen
    Dim $Begin_Zahlenwerte = 0
    Dim $Zaehler = 0
    Dim $Firstsplit = 100
    While 1
    $Zeile = FileReadLine($Input)
    If @error = -1 Then ExitLoop
    $Split = StringSplit($Zeile, @TAB)
    $Zaehler = $Zaehler + 1
    GUICtrlSetData($Label_Zaehler, $Zaehler)

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

    Dim $Ausgeben = 1
    Dim $Zeile_original = $Zeile

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

    If ($Begin_Zahlenwerte == 1) Then

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

    ;Zeile zerlegen
    $pos = StringInStr($Zeile, Chr(9))
    $timestamp = Int(StringMid($Zeile, 1, $pos - 1))
    $Zeile = StringMid($Zeile, $pos + 1)

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

    $pos = StringInStr($Zeile, Chr(9))
    $found = StringMid($Zeile, 1, $pos - 1)
    $Zeile = StringMid($Zeile, $pos + 1)

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

    ; if ($found <> "both") then
    ; $Ausgeben = 0
    ; endif

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

    If ($Ausgeben == 1) Then
    Dim $Anfangszeit = 0
    Dim $Endszeit = 0

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

    $Ausgeben = 0
    $Anfangszeit = 80189
    $Endzeit = 114555
    If ($timestamp >= $Anfangszeit And $timestamp <= $Endzeit) Then $Ausgeben = 1
    ; hier soll Leerzeile dazwischen

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

    $Anfangszeit = 164673
    $Endzeit = 199040
    If ($timestamp >= $Anfangszeit And $timestamp <= $Endzeit) Then $Ausgeben = 1

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

    EndIf
    EndIf

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

    If ($Zeile == "Timestamp Found GazepointX GazepointY") Then
    $Begin_Zahlenwerte = 1
    EndIf

    If ($Ausgeben == 1) Then
    If $Split[1] > $Firstsplit Then
    $Firstsplit += 100
    FileWriteLine($Output, @CRLF & $Zeile_original)
    Else
    FileWriteLine($Output, $Zeile_original)
    EndIf
    EndIf
    WEnd
    GUIDelete()
    MsgBox(0, "Fertig", "Bin fertig!")
    Exit

    [/autoit]
  • Nee, das hab ich nicht gemeint. Nach dem skript wird die gesamte Originaldatei in 5er-Paketen wiedergegeben. Aber die auswahl von bestimmten Zeitbereichen funktioniert dann nicht mehr.

    Ich möchte nur die angegebenen Zeitbereiche aus der Originaldatei rausziehen und beim übergang von einem Zeitbereich auf den anderen eine Leerzeile.

    Die Definition der Zeitbereiche im Skript:

    [autoit]

    If ($Ausgeben == 1) Then
    Dim $Anfangszeit = 0
    Dim $Endszeit = 0
    $Ausgeben = 0
    $Anfangszeit = 80189
    $Endzeit = 114555
    If ($timestamp >= $Anfangszeit And $timestamp <= $Endzeit) Then $Ausgeben = 1
    ; hier soll Leerzeile dazwischen
    $Anfangszeit = 164673
    $Endzeit = 199040
    If ($timestamp >= $Anfangszeit And $timestamp <= $Endzeit) Then $Ausgeben = 1
    EndIf
    EndIf

    [/autoit]


    soll folgendes Ergebnis liefern:


    Wenn das nicht geht, müsste ich für jeden Zeitbereich ein extra skript laufen lassen (oh weh, 20 mal 24 = 480 skripte)

    Aber schon mal danke für die Mühe!!!

  • Ich hab das Script von neu auf geschrieben, es sollte nun einfacher zu warten sein, oben gibt es ein Array "$BEREICHE" wo du weitere Bereiche hinzufügen kannst, der erste Parameter ist der Anfang, der zweite das Ende.

    Spoiler anzeigen
    [autoit]

    Opt("MustDeclareVars",1)

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

    ; ----------
    ; Variablen
    ; ----------
    Const $INPUTFILE = "HT1_1EFD.txt"
    Const $OUTFILE = "HT1_1_cut.txt"

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

    Local $lab_info
    Local $input,$output,$counter,$line
    Local $timestamp,$len,$active

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

    Enum $START,$END
    Const $BEREICHE[2][2] = _
    [ _
    [80189,114555], _
    [164673,199040] _
    ]
    $len = UBound ($BEREICHE)-1
    ; ----------
    ; Script
    ; ----------
    GUICreate("Daten filtern",200,40,-1,-1,BitOR(0x80000000,0x00C00000),-1,0)
    $lab_info = GUICtrlCreateLabel("",5,5,180,60)
    GUISetState(@SW_SHOW)

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

    ; open both files
    $input = FileOpen($INPUTFILE,0)
    If $input == -1 Then
    MsgBox(48,"Error","Unable to open file.")
    Exit
    EndIf
    $output = FileOpen($OUTFILE,2)
    If $output == -1 Then
    MsgBox(48,"Error","Unable to open file.")
    Exit
    EndIf

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

    ; loop of death :)
    $counter = 0
    $active = 0
    While 1
    $line = FileReadLine($input)
    If @error = -1 Then ExitLoop

    GUICtrlSetData($lab_info,$counter)

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

    If Not StringInStr($line,"Both") And _
    Not StringInStr($line,"None") And _
    Not StringInStr($line,"LeftOnly") And _
    Not StringInStr($line,"RightOnly") _
    Then

    ContinueLoop
    EndIf

    $timestamp = Number(StringMid($line,1,StringInStr($line,@TAB)))

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

    For $i=0 To $len Step 1
    If $timestamp >= $BEREICHE[$i][$START] And $timestamp <= $BEREICHE[$i][$END] Then
    If $active <> $i Then
    FileWrite($output,@CRLF&$line&@CRLF)
    $active += 1
    Else
    FileWrite($output,$line&@CRLF)
    EndIf
    EndIf
    Next

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

    $counter+=1
    WEnd
    FileClose($input)
    FileClose($output)

    [/autoit]

    EDIT: paar Fehler behoben, jetzt funktionierts

    5 Mal editiert, zuletzt von bluelamp (25. Oktober 2008 um 23:14)