Sort_by_Column_Letter

<< Click to Display Table of Contents >>

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

Sort_by_Column_Letter

TXT.Sbcl

Previous Top Next


MiniRobotLanguage (MRL)

 

TXT.Sbcl

TXT.Sort_by_Column_Letter

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

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

 

clip0353

 

$$IND="A"

' Start in Line 2 to keep the header

$$STA=2

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

 

Result:

clip0352

 

 

$$IND="A"

' Start in Line 2

$$STA=2

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

 

Result:

clip0354

 

 

 

This command has been optimized for Speed. Even large Files with 40 MB in Size should be sorted within 1-2 Seconds or less.

I have tested with a file that contained >350.000 Lines and it sorted instantly.

 

 

 

Syntax

 

 

TXT.Sbcl|P1|P2[|P3][|P4]

TXT.Sort_by_Column_Letter|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