uniq command takes in a sorted file and reports duplicated lines. With the proper options, it can be used to omit or report unique or repeated lines.
If we use the
uniq command on an unsorted list, it will report unexpected results, so make sure you
$ sort test.txt | uniq
The example file here simply lists the names of a few people. If we
sort then call uniq, it will return all names in the file, just once.
$ cat names.txt Bob Chase Jon Clara Bob Theresa Jon Billy Jonathan Clara Jonathan Bob Jonny $ sort names.txt | uniq Billy Bob Chase Clara Jon Jonathan Jonny Theresa
To output lines that have repeated elements, we pass in the
$ sort names.txt | uniq -d Bob Clara Jon Jonathan
To output lines that occur just once, pass in the
$ sort names.txt | uniq -c Billy Chase Jonny Theresa
-c option, we can find how many times each occurrence occurs.
$ sort names.txt | uniq -c 1 Billy 3 Bob 1 Chase 2 Clara 2 Jon 2 Jonathan 1 Jonny 1 Theresa
Here are a list of the most-used options. Check out the
man page for more.
-d- output only unique lines. This is the default setting.
Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.$ Check price
Command Line Kung Fu is packed with dozens of tips and practical real-world examples. You won't find theoretical examples in this book. The examples demonstrate how to solve actual problems. The tactics are easy to find, too. Each chapter covers a specific topic and groups related tips and examples together.$ Check price