You are here: Job and Form Set Rules Reference > JDT Rules Reference > SortBatches > Sorting with Multiple Keys

Sorting with Multiple Keys

When you sort with multiple keys, the system does not use an interim file with a prepended key. Instead it writes a temporary batch file for input into the external sort. The SortCommand specified here calls a GNU Sort:

< SortBatchOptions >

BuildSortKey = No

SortCommand = sort -o **TargetFile** *{[[ ]] -k **FieldOffset**, **FieldLength** }* **SourceFile**

The data between the “*{“ and “}*” (in bold) is replicated for each sort field specified in the sort batches entry. The data between the “[[“ and “]]” is used as a field separators.

SortCommand = sort -o **TargetFile** *{[[ ]] -k **FieldOffset**, **FieldLength** }* **SourceFile**

**FieldOffset** and **FieldLength** are replacement strings you can use inside a repeating section. See Replacement Strings for a complete list of available replacement strings.

Given the sample INI values defined above and the sample RCB DFD file definition, the generated sort command would appear as follows:

sort -o .\data\AGENT.wrk -k 1,22 -k 23,4 -k 27,45 .\data\AGENT.tmp

Sorting with an OptTech Sort

OTSort by OptTech is a third-party sort utility. Here is an example of how you could set the SortCommand options to execute OTSort with the SortBatches rule:

< SortBatchOptions >

BuildSortKey = No

SortCommand = OTSW32D **SourceFile** **TargetFile** /S(*{[[,]]**FieldOffset**,**FieldLength**,**FieldType**,**SortType**}*)