You can use the uniq command to omit repeated lines in a file. For example, notice that the line Cherries are red. is included four times in the file facts.txt:
To view facts.txt without repeated lines, you can run:
elliot@ubuntu-linux:~$ uniq facts.txt
Apples are red.
Grapes are green.
Bananas are yellow.
Cherries are red.
Sky is high.
Earth is round.
Linux is awesome!
Cherries are red.
Grass is green.
Swimming is a sport.
Notice that Cherries are red. is still shown twice in the output. That’s because the uniq command only omits repeated lines but not duplicates! If you want to omit duplicates, you have to sort the file first and then use a pipe to apply the uniq command on the sorted output:
elliot@ubuntu-linux:~$ sort facts.txt | uniq
Apples are red.
Bananas are yellow.
Cherries are red.
Earth is round.
Grapes are green.
Grass is green.
Linux is awesome!
Sky is high.
Swimming is a sport.
Boom! We have successfully omitted repeated and duplicate lines.