Jump to content

Txt file sorting


ubuy
 Share

Recommended Posts

Well,

i have a file .txt in this format.

| ΔΡΑ.001 | ΓΡΗΓΟΡΙΑΔΗΣ ΜΙΧΑΗΛ | ΑΓΙΟΣ ΑΘΑΝΑΣΙΟΣ | ΣΟΥΠΕΡ ΜΑΡΚΕΤ | 052072969 | ΔΡΑΜΑΣ | 0,00 |

| ΔΡΑ.002 | ΓΙΑΛΑΜΑΣ ΔΗΜΗΤΡΙΟΣ | ΒΕΡΓΙΝΑΣ 13 | | 021874447 | ΔΡΑΜΑΣ | 0,00 | |

| ΔΡΑ.004 | ΘΕΟΔΩΡΙΔΟΥ ΝΙΚΗ & ΣΙΑ ΟΕ | ΚΕΦΑΛΑΡΙ | | 082478667 | ΔΡΑΜΑΣ | 0,00 | |

| ΔΡΑ.006 | ΠΕΤΡΟΠΟΥΛΟΣ ΓΕΩΡΓΙΟΣ | ΤΕΡΜΑ ΧΡΥΣΟΒΕΡΓΗ | | 046481515 | ΔΡΑΜΑΣ | 0,00 | |

I want to delete all the | from the text , justify them at will , change the first field to a number ascending 0001 to whatever , sort them , combine the first field with the second and export them to an other text file called pel.txt

This is how i want it to see. I attached 2 files. Before and after.

0001ΓΡΗΓΟΡΙΑΔΗΣ ΜΙΧΑΗΛ ΑΓΙΟΣ ΑΘΑΝΑΣΙΟΣ ΣΟΥΠΕΡ ΜΑΡΚΕΤ 052072969 ΔΡΑΜΑΣ 0,00

0002ΓΙΑΛΑΜΑΣ ΔΗΜΗΤΡΙΟΣ ΒΕΡΓΙΝΑΣ 13 021874447 ΔΡΑΜΑΣ 0,00

0003ΘΕΟΔΩΡΙΔΟΥ ΝΙΚΗ & ΣΙΑ ΟΕ ΚΕΦΑΛΑΡΙ 082478667 ΔΡΑΜΑΣ 0,00

0004ΠΕΤΡΟΠΟΥΛΟΣ ΓΕΩΡΓΙΟΣ ΤΕΡΜΑ ΧΡΥΣΟΒΕΡΓΗ 046481515 ΔΡΑΜΑΣ 0,00

Is this possible ?

Can anyone from you make it ?

Thanks in advance

text_files.zip

Link to comment
Share on other sites

I have no luck. String split does not work for me. Please help me.

This my code so far with no luck

#include <file.au3>

#include <array.au3> ; only for _ArrayDisplay()

$sFile = "C:\CL\DATA\winLAGAK1.txt"

$file = FileOpen("C:\CL\DATA\winLAGAK1.txt", 0)

Dim $text,$newarray

$i=0

; Read in how many line there are

While 1

FileReadLine($file)

If @error = -1 Then ExitLoop

$i=$i+1

Wend

FileClose($file)

; Read file to array and delte first 10 records

If Not _FileReadToArray($sFile, $text) Then

MsgBox(4096, "Error", " Error reading text file to Array error:" & @error)

Exit

EndIf

$i=0

For $i = 1 to 30 step 1

_ArrayDelete($text,0)

$i=$i+1

Next

;DELETE LAST RECORDS

_ArrayDelete($text,1131-16)

_ArrayDelete($text,1131-15)

_ArrayDelete($text,1131-14)

$array =StringSplit ( $TEXT, @TAB )

_ArrayDisplay($ARRAY, "Debug: $text")

_ArrayDisplay($TEXT, "Debug: $text")

Link to comment
Share on other sites

  • 2 weeks later...

Anyone? Please help...

How can i create a multidimensional array so i can split my text line to fields ? Or maybe how can i split my text line to mdb fields ?

Work with $temporary_string to get the output into the file that you desired, i don't have time for that :P

#include <GUIConstants.au3>
#include <array.au3>
#include <file.au3>
#include <String.au3>

Global $file_to_read = "C:\before.txt"
Global $file_to_put = "C:\after.txt"
Global $array_file, $array_output_file[1]


_FileReadToArray($file_to_read, $array_file)

For $a = 1 To $array_file[0]
    $temporary_array = StringSplit($array_file[$a], "|")
    If $temporary_array[0] = 10 Then
        $temporary_string = _NumberConversion($a, $array_file[0]) & @TAB & $temporary_array[2] & @TAB & $temporary_array[3] & @TAB & $temporary_array[4] & @TAB & $temporary_array[5] & @TAB & _
        $temporary_array[6] & @TAB & $temporary_array[7] & @TAB & $temporary_array[8] & @TAB & $temporary_array[9] & @TAB & $temporary_array[10]
        ConsoleWrite(@CR & $temporary_string)
        If $temporary_string <> "" Then
            _ArrayAdd($array_output_file, $temporary_string)
            _FileWriteFromArray($file_to_put, $array_output_file)
        EndIf
    Else
        ; Ignore
    EndIf
Next
$array_output_file[0] = UBound($array_output_file) - 1

Func _NumberConversion($temp_number, $max_digits)
    If StringLen($temp_number) <> StringLen($max_digits) Then
        Do
            $temp_number = _StringInsert("" & $temp_number & "", "0", 0)
            If @error Then MsgBox(0, 1, @error)
        Until StringLen($temp_number) = StringLen($max_digits)
        Return $temp_number
    Else
        Return $temp_number
    EndIf
EndFunc   ;==>_NumberConversion

My little company: Evotec (PL version: Evotec)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...