What does the Text Sorter do?
The Text Sorter arranges multiline text lists, log entries, CSV rows, and code elements according to alphabetical order (A–Z or Z–A), natural numeric sequence (e.g. 2 before 10), case sensitivity settings, and optional duplicate line removal.
Core Concepts
Understanding text line sorting algorithms and collation rules:
- Alphabetical Collation: Orders lines based on standard unicode lexical values (ascending A–Z or descending Z–A).
- Natural Numeric Sorting: Evaluates numerical digits inline using integer values (sorting
file2.txtbeforefile10.txt). - Case Sensitivity Controls: Distinguishes between uppercase and lowercase letters (
Applevsapple) or performs case-insensitive collation. - Concurrent Deduplication: Filters out redundant duplicate lines during the sort operation.
How to use the tool?
- Enter Text Lines: Enter or paste your multiline text or log output into the editor or click Load Sample.
- Configure Sort Options:
- Choose your Order direction (Ascending or Descending).
- Toggle Case-Sensitive, Natural Numeric Sorting, or Remove Duplicates.
- Sort & Copy: Click Sort Text Lines, then click Copy or Download to save your sorted text.
Related Developer Utilities
If you work with text processing, line formatting, and deduplication, explore these complementary tools:
- Duplicate Line Remover: Strip duplicate lines while preserving original line order.
- Add Line Numbers: Prepend customizable line numbers and prefixes to text.
- Text Case Converter: Convert text between camelCase, snake_case, PascalCase, and kebab-case.
- Text Whitespace Cleaner: Normalize spaces, tabs, and line endings.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/text/text-sorter) to programmatically sort multiline text list elements based on configurable sorting directions and collation strategies.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Multiline text block to sort. | "Pear\nApple\nOrange" |
direction |
String | Sort direction: "asc" or "desc". Default: "asc". |
"asc" |
caseSensitive |
Boolean | True to distinguish uppercase/lowercase. Default: false. |
false |
numericNatural |
Boolean | True for natural math ordering (2 before 10). Default: true. |
true |
removeDuplicates |
Boolean | True to strip duplicate lines. Default: false. |
false |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/text/text-sorter \
-H "Content-Type: application/json" \
-d '{
"rawText": "Pear\n10 apples\nApple\n2 apples",
"direction": "asc",
"caseSensitive": false,
"numericNatural": true,
"removeDuplicates": true
}'Python
import requests
url = "https://blueutils.com/api/text/text-sorter"
payload = {
"rawText": "Pear\n10 apples\nApple\n2 apples",
"direction": "asc",
"caseSensitive": False,
"numericNatural": True,
"removeDuplicates": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "Pear\\n10 apples\\nApple\\n2 apples",
"direction": "asc",
"numericNatural": true,
"removeDuplicates": true
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/text/text-sorter"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether sorting completed successfully. | true |
result |
String | Collation-sorted output text lines. | "2 apples\n10 apples\nApple\nPear" |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "2 apples\n10 apples\nApple\nPear"
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Input text payload must be a string."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to sort text?
Integrating the Text Sorter API into data cleaning pipelines, log analyzers, or AI agent tool calling provides essential advantages:
- Rapid Script Validation: Normalizes messy output lists, environment variables, and log extracts into predictable ordered sequences.
- Optimized Token Efficiency for AI Agents: LLMs frequently introduce subtle collation errors and misplace numbers when sorting lists. Invoking the API sorts thousands of lines deterministically without token hallucinations.
- Deterministic Accuracy Without Hallucinations: Ensures 100% accurate natural numeric evaluation and unicode-compliant sorting.
Native Usage
How to sort text lists locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Sort text lines in PowerShell
Get-Content input.txt | Sort-Object | Set-Content sorted.txtLinux / Unix (Bash)
# Sort text lines alphabetically in Linux
sort input.txt > sorted.txt
# Sort text lines with natural version/number sorting
sort -V input.txt > sorted.txtPython
Using Python sorted:
with open("input.txt", "r", encoding="utf-8") as f:
lines = f.readlines()
sorted_lines = sorted(lines, key=lambda s: s.strip().lower())
with open("sorted.txt", "w", encoding="utf-8") as f:
f.writelines(sorted_lines)
print("Text sorted successfully.")Java
Using Java Collections.sort:
import java.nio.file.*;
import java.util.*;
public class TextSorterExample {
public static void main(String[] args) throws Exception {
List<String> lines = Files.readAllLines(Paths.get("input.txt"));
Collections.sort(lines, String.CASE_INSENSITIVE_ORDER);
Files.write(Paths.get("sorted.txt"), lines);
System.out.println("Text sorted successfully.");
}
}