terminal.cab

All commands

sort

Topic: Text

Program: sort

Sorts lines.

Package: text-sort

Usage

sort [OPTION]... [FILE]...

Description

Put the lines of all FILEs together in order and print them. A FILE named -, or no FILE, means the keyboard or pipe. Without -t, a field starts with the spaces before it.

Options in the simulator

17 more options of the real program, not in the simulator yet
  • -d, --dictionary-order not in the simulator yet

    On a real system sort then compares only letters, digits and spaces.

  • -g, --general-numeric-sort not in the simulator yet

    On a real system sort also compares numbers written like 1e3.

  • -i, --ignore-nonprinting not in the simulator yet

    On a real system sort then skips control characters.

  • -R, --random-sort not in the simulator yet

    On a real system sort shuffles the lines, equal lines stay together.

  • --random-source needs a value not in the simulator yet

    On a real system sort shuffles the lines, equal lines stay together.

  • --sort needs a value not in the simulator yet

    On a real system it picks the kind of comparison by name, such as --sort=numeric.

  • --batch-size needs a value not in the simulator yet

    On a real system it only changes how sort works inside (memory, temporary files); the output stays the same.

  • -C not in the simulator yet

    On a real system sort checks like -c whether the input is sorted, but prints nothing; only the exit status tells.

  • --compress-program needs a value not in the simulator yet

    On a real system it only changes how sort works inside (memory, temporary files); the output stays the same.

  • --debug not in the simulator yet

    On a real system sort then marks which part of each line it compares.

  • --files0-from needs a value not in the simulator yet

    On a real system sort reads the names of its inputs from a file.

  • -m, --merge not in the simulator yet

    On a real system sort only merges files that are already sorted.

  • -S, --buffer-size needs a value not in the simulator yet

    On a real system it only changes how sort works inside (memory, temporary files); the output stays the same.

  • -T, --temporary-directory needs a value not in the simulator yet

    On a real system it only changes how sort works inside (memory, temporary files); the output stays the same.

  • --parallel needs a value not in the simulator yet

    On a real system it only changes how sort works inside (memory, temporary files); the output stays the same.

  • -z, --zero-terminated not in the simulator yet

    On a real system a zero byte instead of a newline ends each line, for names from find -print0.

  • --version not in the simulator yet

    On a real system it prints the version of the program.

Examples

From the lesson Chaining commands
sort notes.txt Documents/notes.txt | uniq -c
      2 Buy milk
      1 Call the dentist
      1 Water the plants

Try it in the terminal

From the lesson Sort and count
sort -t, -k3 -n orders.csv
customer,city,amount
finn,Hamburg,15
cem,Berlin,45
eva,Berlin,60
ben,Hamburg,80
hugo,Cologne,95
anna,Berlin,120
dana,Munich,200
gina,Berlin,300
sort -t, -k3 -rn orders.csv | head -n 2
gina,Berlin,300
dana,Munich,200

Try it in the terminal

From the lesson Sort and count
uniq -c visitors.txt
      1 10.0.0.5
      1 10.0.0.9
      2 10.0.0.5
      1 10.0.0.7
      1 10.0.0.9
      1 10.0.0.5
      1 10.0.0.9
sort visitors.txt | uniq -c
      4 10.0.0.5
      1 10.0.0.7
      3 10.0.0.9

Try it in the terminal

From the command of the day: sort | uniq -c | sort -rn
sort visitors.txt | uniq -c | sort -rn
      3 anna
      2 ben
      1 carla

Try it in the terminal

Where you learn it

Lessons

Command of the day

All commands