Site icon LinuxCommands.site

uniq command tutorial in linux/unix with examples and use cases

linux uniq command – report or omit repeated lines.

Linux uniq command, which usually requires sorted input, compares and ranks only on adjacent lines.

syntax

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

options

Examples

Remove adjacent duplicates using uniq command

➜ uniq test.log

Remove duplicates using sort and uniq commands

➜ sort test.log | uniq

Remove duplicates and count duplicates

➜ sort test.log | uniq -c
      3 hello 99
      5 test 73
      2 ylspirit 78

Show only duplicate rows

➜  uniq sort test.log | uniq -d

Exit mobile version