terminal.cab

All commands

uniq

Topic: Text

Program: uniq

Merges equal lines that follow each other.

Package: text-sort

Usage

uniq [OPTION]... [INPUT [OUTPUT]]

Description

Print the lines of INPUT, but equal lines that follow each other only once. Without INPUT, or with -, read the keyboard or pipe.

Options in the simulator

6 more options of the real program, not in the simulator yet
  • -D not in the simulator yet

    On a real system uniq then prints every line of a group of equal lines, not just the first.

  • --all-repeated value optional not in the simulator yet

    On a real system uniq then prints every line of a group of equal lines, not just the first.

  • --group value optional not in the simulator yet

    On a real system uniq then prints all lines, with an empty line between groups.

  • -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.

  • -w, --check-chars needs a value not in the simulator yet

    On a real system uniq then compares only the first N characters of each line.

  • --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
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