<< Click to Display Table of Contents >> Navigation: 3. Script Language > TXT. Text-File Engine |
MiniRobotLanguage (MRL)
TXT. the Text-File Engine
This Engine can parse and change Textfiles or CSV-Files very fast (Example 1600 Lines per Second).
Intention
Assume that you want to do something with a Text- or csv-File.
You want to read "Line-by-Line" and write something out of this.
Maybe remove some fields or sort something.
Normally you you could use the Commands like CFF., LFF., FEL., SBD, etc.
This will work and will also be sufficient fast in most cases.
But there are cases when you have large files with 50.000 or more Lines,
when its just gets very slow, reading Line-by-Line from the harddisk.
Now here comes the TXT.-Engine.
The TXT.- Commands will read the whole file into memory and do all changes and stuff also in memory.
As it does not touch the harddrive during the operation, all commands will be done with full speed.
The TXT.Command can also load and convert Unicode-Textfiles.
All loaded Textfiles must be converted to $crlf$-ending Lines and to ANSI.
For this there are commands available.
If you work on csv-Files, please also take a look on the DCI.-Command.
Using TXT. together with DCI. you can do all sorts of stuff with Csv.-Files in very short time,
and get very fast results.
Some commands like TXT.Sort... and similar have been optimized for Speed and tested with Files up to 360.000 Lines.
Code-Sample
' This Sample is a productive Script which is just a Code-Sample.
' It may only be partidally useful for someone else.
'
'SPR Script-file: Dr_Andreas_Debit_Sample
'Purpose:
'Author: Dr.Andreas
'Creation date: 04-28-2022 at 10:21:39
'===========================================================
'#EXE:?path\
'#SPI:ForceWrite
' Zeilentrenner ist nur $CR
' wieviel treffer der pattern gab es in der datei
' countervarianle $$TRE = TREFFER
$$TRE=0
$$TMA=#dtime#
IEM.
VAR.$$FIA=$cmdexe$
ELS.
VAR.$$FIA=?exeloc\BEISPIEL_1.csv
EIF.
VAR.$$FIB=?exeloc\Tempfile_2.csv
VAR.$$OUF=?exeloc\Result_#date#_awt.csv
NEF.$$FIA
$$ERR=Die Quelldatei: $$FIA$crlf$existiert nicht.
GTO.ero
EIF.
' Feldnummer vonFeld "U" ist 21
$$MAF=21
$$PTA=1500.00
$$PTB=0.01
$$FIK=?exeloc\Test.txt
$$LIA="Q","M","K","I","H",F"
'-----------------------------------------------------------
TXT.Load_Textfile|$$FIA|$$NUL
' Zeilentrenner umwandeln
TXT.crp
TXT.Get_Line_Count|$$NUL
IVV.$$NUL<5
$$ERR=Ist die Datei leer?
GTO.ero
EIF.
DBP.$$NUL Zeilen geladen
'-----------------------------------------------------------
' Finde Ende des Headers
$$HEA=;;Konto;Belegnr;Ar;;Datum;
TXT.Find_Line_with|$$HEA|1|$$LIH
VIC.$$LIH
IVV.$$LIH=0
$$ERR=Header nicht gefunden.
GTO.ero
EIF.
TXT.Get_to_Start|$$LIH|$$HEB
'-----------------------------------------------------------
' Header schreiben
'VAR.$$HEC=$$HEB$crlf$
' leere Datei erzeugen
VAR.$$HEC=$crlf$
CTF.$$OUF|$$HEC
'-----------------------------------------------------------
TXT.Replace|$crlf$|$cr$
:MAIN
' zum testen hier $$NUL patchen
'
'$$NUL=2000
FOR.$$LIN|1|$$NUL
' Die folgende Zeile ist unnötig
' aber verdoppelt die Geschwindigkeit hier von 78 Sek -> 33 Sek.
' diese routine gibt einen optimierten $$LIN zurück
GSB.GetNextFit
GSB.Test_Lit
' wenn der jump ausgeloest wird,
' d.h. es wurde kein pattern gefunden
' so ueberspringt er "nur" den folgenden
' code. ein if then else haette es auch getan :)
JIZ.$$ERG|Loop
' Zeile gefunden, bestimme Position des Start-Debitors
CAL.$$POY=$$LIN-8
$$POY=$$LIN
' Hole Ende-Debitor nach $$LEB
GSB.Find_Deb_End
'DBP. Zeilen: $$POY bis $$LEB
' 828-848 wären OK
VIC.$$TRE
TXT.gtls|$$POY|$$LEB|$$PAA
GSB.Lab_Remove_Cols
''$$PAB=$$PAA$crlf$$crlf$########## $$TRE ##########$crlf$$crlf$
$$PAB=$$PAA$crlf$########## $$TRE ##########$crlf$
ATF.$$OUF|$$PAB
:Loop
NEX.
:enx
CAL.$$TMA=#dsince#|i
MBX.Programm wird beendet nach $$TMA Sekunden.
ENR.
:ero
MBX.$$ERR
GTO.enx
'-----------------------------------------------------------
' Remove unwanted Columns
'
:Lab_Remove_Cols
TXT.Push_Intern
TXT.Load_pure_Text|$$PAA|$$FIK
TXT.Delimited_Items_Remove|;|$$LIA
TXT.Get_pure_Text|$$PAA
TXT.Pop_Intern
RET.
'-----------------------------------------------------------
:Find_Deb_End
$$DEB=Debitor
$$LEB=$$LIN
:Research
IVV.$$LEB>$$NUL
$$END=1
$$LEN=$$NUL
GTO.LeaveResearch
EIF.
' finde die Zeile mit dem Suchpattner $$DEB
' also hier als Content DEBITOR
'
TXT.Find_Line_with|$$DEB|$$LEB|$$DEH
'TXT.Get_Line_Trimmed|$$DEH|$$DET
'SBD.$$DET|;|1|$$DEA
TXT.get_delimited_item_from_line|$$DEH|;|1|$$DEA
VBT.$$DEA|$lf$$sp$
'PRT.<$$DEA>|h
IVS.$$DEA!$$DEB
CAL.$$LEB=$$DEH+1
GTO.Research
EIF.
CAL.$$LEB=$$DEH-1
'PRT.Found at:$$LEB
'MBX.!
:LeaveResearch
RET.
'===========================================================
' prüfe nun ob in der zeile die Pattern
' $$PTA bzw $$PTB vorkommen
' wenn ja, setze dir einen Merker (die 1)
' in die Variable $$ERG
'
:Test_Lit
'TXT.Get_Line_Trimmed|$$LIN|$$LIT
'SBD.$$LIT|;|$$MAF|$$RES
'
TXT.get_delimited_item_from_line|$$LIN|;|$$MAF|$$RES
$$ERG=0
IVV.$$RES=$$PTA
$$ERG=1
EIF.
IVV.$$RES=$$PTB
$$ERG=1
EIF.
RET.
'===========================================================
' ermittel die zeilenummern wo die
' suchpattern $$PTA und $$PTB vorkommen
'
' der kleinere zeilenfundort wird in $$LIN
' geladen, sofern er nicht 0 ist
'
' so kann eine nachfolgende analyse dirkt
' bei $$LIN starten
'
:GetNextFit
CAL.$$SEB=$$LIN+1
TXT.Find_Line_with|;$$PTA|$$SEB|$$FRA
TXT.Find_Line_with|;$$PTB|$$SEB|$$FRB
'PRT.Got: $$FRA - $$FRB from $$SEB
IVV.$$FRA<$$FRB
JIZ.$$FRA|DoFrb
$$LIN=$$FRA
ELS.
:DoFrb
NVV.$$FRB=0
$$LIN=$$FRB
ELS.
$$LIN=$$NUL
EIF.
EIF.
:Leave
'PRT.$$LIN
RET.
'===========================================================
Code Explanation
-
Example
'
'-----------------------------------------------------------
END.
Remarks
-
Limitations:-
-
See also: