GNU/Linux Command – UNIQ

uniq — Remove duplicate lines from a SORTED file.

Summary :
It prints the unique lines in a sorted file. If input is not sorted then, only adjacent duplicate lines are discarded. Create ‘myfile’ with 2 cols of digits for testing.

Example:
$ uniq myfile -- Print only unique lines. $ uniq -i myfile -- Ignore case when comparing. $ uniq -u myfile -- Print only lines, Which is not duplicated. $ uniq -c myfile -- Print all unique lines with no .of occurrence. $ uniq -d myfile -- Print only duplicate lines. If a line isduplicated then, only one line will be printed. $ uniq -D myfile -- Print all duplicate lines. $ uniq -w5 myfile -- Use only first 5 Chars for checking the uniqueness of the line.  $ uniq -f2 myfile -- Don't compare up-to 2nd field.  $ uniq -s2 myfile -- Don't compare up-to 2nd char.  $ sort myfile | uniq > output -- Sort myfile and store the uniqto output.
Read : man uniq

Advertisements
Tagged with: ,
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: