<< Click to Display Table of Contents >> Navigation: 3. Script Language > TXT. Text-File Engine > CSV-Related Commands > Sort_by_Column_Integer |
MiniRobotLanguage (MRL)
TXT.Sbci
TXT.Sort_by_Column_Integer
Treat the internal Buffer as a csv-file and Sort the File "by Column"
Intention
This command is used to work with csv-Files. It will Sort the internal Buffer "by a Column".
Integer Numbers must be treated in a special way to get a correct result.
For example, 900 would alphabetically be sorted after 1000 in a pure "Letter sort",
therefore this command is the solution.
Here we are going to sort by Column "A", ignoring the Headline.
Important: All Data here is fictional and just for demonstrating the SPR-Commands.
$$IND="A"
' Start in Line 2 to keep the header
$$STA=2
TXT.sort_by_column_Integer|$$STA|$$IND|;|a
Result:
$$IND="A"
' Start in Line 2
$$STA=2
$$IND="D"
TXT.sort_by_column_Integer|$$STA|$$IND|;|d
Result:
This command has been optimized for Speed. Even large Files with 40 MB in Size should be sorted within 1-2 Seconds or less.
Syntax
TXT.Sbci|P1|P2[|P3][|P4]
TXT.Sort_by_Column_Integer|P1|P2[|P3][|P4]
Parameter Explanation
P1 - (Input,numeric) Start-Line, because in Line 1 is most often a Header, Startl_line is most often and per default Line 2.
P2 - (Input) Sorting Column. Something like a number like 3 or a letter in "C".
P3 - (Input) Variable with delimiter. Delimiter can be one or multiple characters. If omitted ; is used.
P4 - (Input) Flags a/d/l - Ascending / Descending sort, L - equalcase sort (uses Lowercase internal)
Example
'*****************************************************
' Template for Testing TXT.-Commands
'*****************************************************
' csv-File from:
' https://maloneinstitute-org.translate.goog/wef?_x_tr_sl=en&_x_tr_tl=de&_x_tr_hl=de&_x_tr_pto=wapp
'
$$TMA=#dtime#
IEM.
VAR.$$FIA=$cmdexe$
ELS.
' put your Filename here
VAR.$$FIA=?exeloc\Sources\Preise_Sample.CSV
EIF.
VAR.$$OUF=?exeloc\Result_#date#.csv
NEF.$$FIA
$$ERR=Die Quelldatei: $$FIA$crlf$existiert nicht.
GTO.ero
EIF.
'-----------------------------------------------------------
TXT.Load_Textfile|$$FIA|$$LIC
' Convert $LF to $crlf$ if needed.
'TXT.lfp
TXT.Get_Line_Count|$$LIC
IVV.$$LIC<5
$$ERR=File is empty?
GTO.ero
EIF.
PRT.$$LIC Lines loaded.
'++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++
' Place your Script here
$$IND="A"
TXT.sort_by_column_letter|2|$$IND|;|d
'++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++
' These lines process and save the result.
'TXT.lfr
TXT.Save_File|$$OUF
EXO.$$OUF
'++++++++++++++++++++++++++++++++
'++++++++++++++++++++++++++++++++
:enx
CAL.$$TMA=#dsince#*1000
CAL.$$LIF=($$LIC*1000)/$$TMA|i
$$TXA=$crlf$Processing $$LIF Lines per Second.
IVV.$$TMA>1000
CAL.$$TMA=$$TMA/1000
$$TXT=Programm wird beendet nach $$TMA Sekunden.$$TXA
ELS.
$$TXT=Programm wird beendet nach $$TMA ms.$$TXA
EIF.
MBT.$$TXT|Programm Ende|9|32
ENR.
'-----------------------------------------------------------
:ero
PRT.$$ERR
GTO.enx
'#######################################################################
Remarks
Optimized for speed. Can sort very large files in a Second..
$crlf$ (CarriageReturn/LineFeed) at the end of the loaded File will be stripped before Sorting.
This was necessary to prevent empty lines to get sorted into the result.
Limitations:
-
See also:
• IEF. / NEF. - If - exist - File