Sort_by_Column_Float

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > TXT. Text-File Engine > CSV-Related Commands >

Sort_by_Column_Float

TXT.Sbcf

Previous Top Next


MiniRobotLanguage (MRL)

 

TXT.Sbcf

TXT.Sort_by_Column_Float

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".

Float-Numbers must be treated in a special way to get a correct result.

For example, 4,00E-02 is the same like 0.004 and would alphabetically or even as Integer not properly be sorted.

The same applies to 2.00E+04 which equals 4000 and will also be sorted in the right way using this command.

Here we are going to sort by Column "D", ignoring the Headline.

The german separator "," (e.g. 2,5) will be replaced with the international "." ( e.g. 2.5) before sorting.

 

Important: All Data here is fictional and just for demonstrating the SPR-Commands.

 

clip0359

 

$$IND="A"

' Start in Line 2 to keep the header

$$STA=2

TXT.sort_by_column_Float|$$STA|$$IND|;|a

 

Result:

clip0362

 

 

$$IND="A"

' Start in Line 2

$$STA=2

$$IND="D"

TXT.sort_by_column_Float|$$STA|$$IND|;|d

 

Result:

clip0361

 

 

 

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.Sbcf|P1|P2[|P3][|P4]

TXT.Sort_by_Column_Float|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:

 

    TXT.Load Textfile

    TXT.Clear

    OPT. - Optional Settings

    FIL.Generate numbered Name

    FIL.Move numbered File

    ATF - Append-to-File

    CFF. - Copy-From-File

    CTF - Copy-To-File

    COP. - Copy File

    SHF. - Shell-File-Operation

    MDF. - Make-Direktory-File

    MKD. - Make-Directory

    GLC. - Get-Line-Count

    IEF. / NEF. - If - exist - File

    LFF - Line-From-File

    WFF. - Wait-For-File

    REN. - Rename File/Dir