Sort Lines in Files
Multi Commander's Sort Lines tool is a powerful text processing utility that provides advanced line sorting capabilities for text files. With comprehensive customization options, it can handle complex sorting scenarios including multi-field sorting, date-based sorting, numerical sorting, and sophisticated text processing requirements.

The Sort Lines dialog provides extensive configuration options for precise sorting control
Overview and Capabilities
The Sort Lines tool operates on all selected text files in the Explorer Panel, making it ideal for batch processing. The tool automatically detects and preserves file encoding (ASCII, Unicode, UTF-8) and maintains original line ending formats.
File Processing
Sort Lines processes all selected text files. The dialog shows the number of files to be processed. Binary files are automatically detected and ignored to prevent corruption.
Supported Features
- Multiple file batch processing
- Automatic encoding detection and preservation
- Header and footer line preservation
- Substring and field-based sorting
- Date, number, and text sorting methods
- Language-aware sorting with locale support
- Natural number ordering
- Flexible output file naming
Advanced Options
- Position-based sorting with character offsets
- Item/record-based sorting with separators
- Case-sensitive and case-insensitive modes
- Reverse sorting capabilities
- Leading whitespace handling
- Blank line removal
- Backup file creation
- Preview with position ruler
File Output Options
Filename Configuration
The filename field controls how sorted files are named and saved:
Single File Processing
Enter a specific filename for the sorted output. The original extension is automatically preserved.
Example: Original file "data.txt" → Sorted file "data_sorted.txt"
Multiple File Processing
Use "*" as a placeholder for the original filename. The wildcard represents both filename and extension.
Example: Pattern "*_sorted.*" transforms "file1.txt" → "file1_sorted.txt"
Save Options
The "Save as..." dropdown provides flexible output strategies:
Option | Behavior | Use Case |
---|---|---|
New Name | Create new file with specified name | Keep original files unchanged |
Keep Original | Replace original, rename old file to .bak | Update file while preserving backup |
Delete Original | Replace original file completely | Direct replacement without backup |
Lines and Position Controls
These settings provide precise control over which parts of files are sorted and how:
Header and Footer Preservation
Keep Lines at Top
Specifies the number of lines at the beginning of each file that should remain in their original position.
Example: Set to "2" to preserve a 2-line header while sorting the rest of the content.
Keep Lines at Bottom
Specifies the number of lines at the end of each file that should remain in their original position.
Example: Set to "3" to preserve a 3-line footer while sorting the main content.
Position-Based Sorting
Start at Line Position
Defines the character position where sorting comparison begins on each line.
Use Case: Sort data that has a fixed-width format where the sort key starts at a specific column.
Visual Aid: The preview ruler shows exactly where sorting will begin.
Skip Leading Spaces
Ignores leading whitespace characters when comparing lines during sorting.
Benefit: Ensures consistent sorting regardless of indentation or formatting differences.
Sorting Methods
Sort Lines offers three sophisticated approaches to line comparison:
1. Entire Line Sorting
The most straightforward method that compares complete lines from the specified start position to the end.
Best For:
- Simple alphabetical sorting of text lists
- Sorting file lists or directory contents
- General text organization tasks
2. Substring Sorting
Sorts based on a specific portion of each line, with flexible endpoint definitions:
Fixed Length
Sort based on a substring of exact length
Example: Characters 5-10 for sorting by product codes
End Character
Sort until a specific character is encountered
Example: Sort until ":" for timestamp-based sorting
Whitespace
Sort until any whitespace character
Example: Sort by first word on each line
3. Line Item (Record) Sorting
Advanced sorting for structured data with delimited fields:
Item Separator
Specify the character that separates fields/records on each line.
Common Separators:
- Comma (,): CSV files and comma-separated data
- Tab (\t): Tab-separated values
- Pipe (|): Database export formats
- Semicolon (;): European CSV formats
Item Selection
Choose which field to sort by (1 = first field, 2 = second field, etc.)
Example: For "John,Doe,Manager" separated by commas:
- Item 1: Sort by "John" (first name)
- Item 2: Sort by "Doe" (last name)
- Item 3: Sort by "Manager" (role)
Sort Methods and Data Types
Multi Commander provides three sophisticated sorting algorithms optimized for different data types:
Text Sorting
Function: Standard alphabetical sorting with comprehensive character handling
Features:
- Unicode-aware character comparison
- Configurable case sensitivity
- Language-specific sorting rules
- Natural number ordering support
Date Sorting
Function: Chronological sorting based on date/time values in text format

Configuration Requirements:
- Specify exact date/time format pattern
- Format must match the text representation exactly
- Supports various date conventions (US, European, ISO, etc.)
- Handles time components with high precision
Format Examples:
MM/dd/yyyy
for "12/31/2023"dd-MM-yyyy HH:mm
for "31-12-2023 14:30"yyyy-MM-dd'T'HH:mm:ss
for ISO format
Reference: Date Format Documentation | Time Format Documentation
Number Sorting
Function: Numerical value-based sorting treating text as actual numbers
Behavior:
- Compares numeric values, not text representation
- Automatically ignores leading zeros
- Handles negative numbers correctly
- Supports decimal values and scientific notation
Example: "1", "10", "2", "20" sorts as 1, 2, 10, 20 (not 1, 10, 2, 20)
Advanced Sorting Options
Language and Localization
Language-Based Sort Order
Function: Uses system locale-specific sorting rules
Benefits:
- Handles accented characters correctly
- Respects language-specific alphabetical orders
- Automatically handles case sensitivity
- Ensures culturally appropriate sorting
Note: Slower performance with very large files
Natural Number Order
Function: Sorts embedded numbers in logical sequence
Example Transformation:
- Standard: "Text1", "Text10", "Text2"
- Natural: "Text1", "Text2", "Text10"
Requirement: Must enable Language-based sort order
Use Case: File lists, version numbers, chapter headings
Case and Order Control
Ignore Case
Treats uppercase and lowercase letters as equivalent during sorting.
Result: "Apple", "banana", "Cherry" sorts consistently regardless of capitalization.
Note: Disabled when using language-based sorting (which always ignores case).
Reverse Order
Inverts the sort order for descending results.
Text: Z to A instead of A to Z
Numbers: 9 to 0 instead of 0 to 9
Dates: Newest to oldest instead of oldest to newest
Content Filtering
Remove Blank Lines
Automatically removes empty lines from the sorted output.
Benefit: Cleans up data files by eliminating unnecessary whitespace.
Process: Applied after sorting is complete.
Remove Duplicate Lines
Feature currently in development
Will automatically remove duplicate lines from sorted output when implemented.
Integration and Automation
Command Line Integration
Sort Lines functionality is available through Multi Commander's custom command system:
Parameter | Description | Example Value |
---|---|---|
SORTAS |
Sort method: Text, Number, or Date | Text |
SORTBY |
Sort by: Line, SubString, or Item | Item |
ITEMSEP |
Item separator character | , |
ITEM |
Item number to sort by | 2 |
REVERSE |
Reverse sort order | 1 |
IGNORECASE |
Ignore case differences | 1 |
Troubleshooting Common Issues
- Verify the date format pattern exactly matches your data format
- Check for inconsistent date formats within the same file
- Ensure all dates follow the same format convention
- Test with a small sample file first to verify format correctness
- Consider using substring sorting if dates are at fixed positions
- Change Sort Method from "Text" to "Number"
- Verify that the data contains only numeric values in the sort field
- Check for non-numeric characters (spaces, letters) in the number field
- Consider using Natural Number Order for mixed text/number content
- Use substring or item sorting to isolate the numeric portion
- Check if files are actually text files (binary files are automatically skipped)
- Verify file permissions allow reading and writing
- Ensure files aren't locked by other applications
- Check available disk space for output files
- Verify character encoding compatibility
- Verify the item separator character is correct for your data
- Check that all lines have the same number of fields
- Ensure the item number exists in all lines (count starts from 1)
- Look for inconsistent use of separators (mixing commas and semicolons)
- Test with a simple example to verify separator and item settings
Related Tools and Features
Sort Lines integrates seamlessly with other Multi Commander text processing tools:
- Find and Replace: Clean and standardize data before sorting
- Text Conversion Tools: Standardize line endings and encoding
- File Search: Locate files that need sorting using content criteria
- MultiScript: Automate complex sorting workflows with scripting
Pro Tip
Use the preview ruler in the dialog to visually verify your start position and substring settings before processing. The ruler shows exactly where sorting will begin, helping you avoid off-by-one errors in position-based sorting.
Related Documentation
For more information about Multi Commander's text processing capabilities, see Text Conversion Tools, Find and Replace in Files, and Text Tools Overview.