Linux uniq Command Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-uniq-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Linux have a lot of tools to make daily work of system administrators easy. uniq is one of them. Uniq is a small tool with limited capabilities.

Syntax

Syntax is same as other most of the Linux commands.

Help

Simple and fast help about the options can be get like below.

Help

Help

Example File

While looking various options and features of the uniq command we need some sample text to use in the examples. Below there is file named a.txt file

a.txt

Show Occurrence Count

This will show how many times each line occurred. This will create output by prefixing occurrence count with the lines.

Show Occurrence Count

Show Occurrence Count

Only Print Duplicate Lines

There is another useful options which will show duplicate lines in the text file. This option -d will only show duplicate lines without giving any count.

Only Print Duplicate Lines

Only Print Duplicate Lines

Skip Specified Field From Comparing

We can specify some field for skipping them comparing. This can be useful to set specific text to compare. As we have a text file where This column is the first field most of the lines. We can skip and start from second field. Columns are delimited with spaces or tabs.

LEARN MORE  Best Torrent Clients For Linux

Skip Specified Field From Comparing

Skip Specified Field From Comparing

Skip Specified Chars From Comparing

Some times it can be useful to skip some starting chars from comparison. The index of the starting character can be specified with -s option like below. In this example we will start comparing from 5th character.

Skip Specified Chars From Comparing

Skip Specified Chars From Comparing

Ignore Case

Sort command is by default case sensitive. Case sensitivity behaves differently for uppercase and lowercase characters. This default case sensitivity can be disabled with -i character like below.

Only Print Unique Lines

One of the most popular usage is printing only unique lines. Only unique lines can be printed with -u options.

Version

Version can be printed with --version option.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-uniq-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)