LangStop
sort
Ready
Editor

Configuration

Sort lines of text files

Required
Flags & Options

Add flags from the picker below...

Tests

-n
Numeric sort

Compare fields as numeric values rather than strings (-n / --numeric-sort).

-g
General numeric sort

Compare as general floating-point numbers (handles scientific notation) (-g / --general-numeric-sort).

-h
Human numeric sort

Sort human-readable numbers like 2K, 1G (-h / --human-numeric-sort).

-V
Version sort

Sort version numbers naturally, e.g. 1.2 < 1.10 (-V / --version-sort).

-M
Month sort

Sort by abbreviated month name (JAN < FEB … < DEC) (-M / --month-sort).

-R
Random sort

Shuffle lines randomly but group identical lines together (-R / --random-sort).

-r
Reverse

Reverse the result of comparisons (-r / --reverse).

-f
Ignore case

Fold lower-case to upper-case before comparing (-f / --ignore-case).

-i
Ignore non-printable

Ignore non-printable characters (-i / --ignore-nonprinting).

-b
Ignore leading blanks

Ignore leading whitespace when comparing (-b / --ignore-leading-blanks).

-d
Dictionary order

Consider only blanks and alphanumeric characters (-d / --dictionary-order).

-k
Sort key

Sort via the specified key FIELD[.CHAR][OPTS][,FIELD[.CHAR][OPTS]]. Can be repeated for multi-key sorts (-k / --key).

-t
Field separator

Use the specified character to separate fields (-t / --field-separator).

-u
Unique

Output only the first occurrence of lines that are equal under the comparison (-u / --unique).

-s
Stable sort

Stabilize sort by disabling last-resort comparison so that identical lines remain in input order (-s / --stable).

-o
Output file

Write output to the specified file instead of stdout (-o / --output). Safe to use with the same input file.

-c
Check (strict)

Check that input is already sorted; exit non-zero if not. Does not produce output (-c / --check).

-C
Check (quiet)

Like -c but no error message is printed — only the exit code indicates whether the file is sorted (-C / --check=quiet).

-m
Merge sorted files

Merge already-sorted files; do not sort (-m / --merge).

--parallel
Parallel threads

Change the number of sorts run concurrently to N (default: number of available processors).

-S
Buffer size

Use the specified amount of main memory for sorting, e.g. 512M or 2G (-S / --buffer-size).

-T
Temp directory

Use the specified directory for temporary files (-T / --temporary-directory).

--compress-program
Compress temp files with

Compress temporary files using the specified program; decompress with the same program called with -d.

-z
NUL line terminator

Use NUL (\0) as the line delimiter for null-separated input/output (-z / --zero-terminated).

--batch-size
Merge batch size

Merge at most N inputs at once; for larger merges a tree of merges is used.

--random-source
Random source file

Use the specified file as the source of random bytes for -R.

Live Output

Command
sort -

PRO TIP:Use -k with a range: sort -k2,2n -k1,1 sorts numerically by field 2, then lexically by field 1.

UTF-8
LangStop DevTools v1.0.0
;

Linux sort Command Builder (Online Tool + Complete Guide)

The Linux sort command is a powerful utility used to sort lines of text files based on alphabetical, numerical, or custom criteria. This interactive Sort Command Builder helps you generate accurate commands instantly for working with logs, datasets, and structured text.


🚀 What is the sort Command?

The sort command allows you to:

  • Sort text alphabetically or numerically
  • Sort based on specific columns
  • Handle large files efficiently
  • Combine with pipelines for data processing

⚙️ Basic Syntax

sort [options] file.txt

Example

sort names.txt

🧠 How to Use This Sort Command Builder

This tool helps you:

  • Paste or upload input data
  • Configure sorting options
  • Generate a ready-to-use sort command

Workflow

  1. Enter or paste your data
  2. Choose sorting type (alphabetical, numeric, etc.)
  3. Set advanced options (column, delimiter)
  4. Copy and run the generated command

🔧 Common sort Options

Alphabetical Sort (Default)

sort file.txt

Numeric Sort

sort -n numbers.txt
  • -n → numeric sort

Reverse Sort

sort -r file.txt
  • -r → reverse order

Sort by Column

sort -k 2 file.txt
  • -k → specify column

Custom Delimiter

sort -t ',' -k 2 data.csv
  • -t → delimiter

Unique Sort (Remove Duplicates)

sort -u file.txt

Case-Insensitive Sort

sort -f file.txt

Stable Sort

sort -s file.txt
  • Maintains original order for equal elements

📊 Practical Examples

Sort CSV by Second Column

sort -t ',' -k 2 data.csv

Numeric Reverse Sort

sort -nr numbers.txt

Remove Duplicates While Sorting

sort -u data.txt

Sort Logs by Timestamp Column

sort -k 1 logs.txt

🧩 Common Use Cases

📊 Data Processing

  • Sort CSV or TSV files
  • Prepare datasets for analysis

📜 Log Analysis

  • Sort logs by time or severity

🔗 Shell Pipelines

  • Combine with:
    • cut
    • awk
    • uniq

Example:

cat data.txt | sort | uniq

⚡ Performance Tips

  • Use sort for:
    • Large datasets (optimized internally)
  • Combine with:
    • uniq for deduplication
  • Use -k carefully for correct column sorting
  • For huge files:
    • consider memory usage

⚠️ Common Mistakes

  • Sorting numbers without -n
  • Incorrect column indexing (starts from 1)
  • Forgetting delimiter in structured data
  • Assuming stable sort without -s

🔍 sort vs uniq vs awk

Tool Purpose
sort Ordering data
uniq Removing duplicates
awk Advanced processing

❓ FAQ

What does sort do in Linux?

  • It sorts lines of text files based on specified criteria.

How do I sort numbers correctly?

  • Use -n for numeric sorting.

How do I remove duplicates?

  • Use -u or combine with uniq.

Can sort handle large files?

  • Yes, it is optimized for large datasets.

🧠 Pro Tips

  • Combine sort with pipelines for powerful workflows
  • Use -k with delimiter for structured data
  • Use -u for quick deduplication

🔗 Related Linux Commands

  • cut → extract columns
  • uniq → filter duplicates
  • awk → advanced processing

🏁 Summary

The Linux sort command is:

  • ⚡ Fast and efficient
  • 🎯 Flexible and powerful
  • 🧩 Essential for data processing

Use this Sort Command Builder to generate commands instantly and streamline your workflow.