Linux – How to filter out unique results from grep output

command linelinuxUbuntu

In linux, I can grep a string from a file using grep mySearchString myFile.txt.
How can I only get the result which are unique?

Best Answer

You can achieve this with the sort and uniq utilities.

example:

[john@awesome ~]$ echo -e "test\ntest\ntest\nanother test\ntest"
test
test
test
another test
test
[john@awesome ~]$ echo -e "test\ntest\ntest\nanother test\ntest" | sort | uniq
another test
test

depending on the data you may want to utilize some of the switches as well.

Related Question