How to prevent grep from printing the same string multiple times?

Trae

If I grep a file containing the following:

These are words
These are words
These are words
These are words

...for the word These, it will print the string These are words four times.

How can I prevent grep from printing recurring strings more than once? Otherwise, how can I manipulate the output of grep to remove duplicate lines?

John1024

The Unix philosophy is to have tools that do one thing and do them well. In this case, grep is the tool that selects text from a file. To find out if there are duplicates, one sorts the text. To remove the duplicates, one uses the -u option to sort. Thus:

grep These filename | sort -u

sort has many options: see man sort. If you want to count duplicates or have a more complicated scheme for determining what is or is not a duplicate, then pipe the sort output to uniq: grep These filename | sort | uniq and see manuniq` for options.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to prevent logger printing same information multiple times?

From Java

How to prevent grep from printing a trailing newline?

From Dev

How to prevent SQL Server from running the same subquery multiple times

From Dev

grep keeps printing the same string

From Dev

How to prevent Azure webjob processing same message multiple times concurrently

From Dev

tkinter Button printing same thing multiple times

From Dev

.NET how to prevent calling a method returning a string multiple times

From

Stop console printing the same message multiple times when inputting an string instead of integer

From Dev

How to prevent this warning message from revealing multiple times

From Dev

How to prevent sending login request multiple times from a form

From Dev

How to prevent BluetoothGattCallback from being executed multiple times at a time

From Dev

How to prevent Vue from loading the data multiple times?

From Dev

ReactJs : How to prevent componentWillUpdate from re-rendering multiple times

From Dev

How to prevent function/event from firing multiple times

From Dev

How do I grep a exact string from multiple files at the same time?

From Dev

Prevent same activity to be started multiple times

From Dev

prevent same fragment multiple times in backstack

From Dev

Electron prevent opening same window multiple times

From Dev

JS: How to match one capture group multiple times in the same string?

From Dev

How can I iteratively partition the same string multiple times?

From Dev

How to declare the same string value multiple times inside an array?

From Dev

Bash: How can I grep a line for multiple instances of the same string?

From Dev

How do I read multiple times from same line in stdin?

From

How to read multiple times from same io.Reader

From Dev

How to get same key multiple times from json response?

From Dev

Prevent eventListener from firing multiple times

From Dev

Javascript - prevent function from executing multiple times

From Dev

Prevent Form from opening multiple times

From Dev

Printing characters(with delay) on the same widget multiple times in Tkinter

Related Related

  1. 1

    How to prevent logger printing same information multiple times?

  2. 2

    How to prevent grep from printing a trailing newline?

  3. 3

    How to prevent SQL Server from running the same subquery multiple times

  4. 4

    grep keeps printing the same string

  5. 5

    How to prevent Azure webjob processing same message multiple times concurrently

  6. 6

    tkinter Button printing same thing multiple times

  7. 7

    .NET how to prevent calling a method returning a string multiple times

  8. 8

    Stop console printing the same message multiple times when inputting an string instead of integer

  9. 9

    How to prevent this warning message from revealing multiple times

  10. 10

    How to prevent sending login request multiple times from a form

  11. 11

    How to prevent BluetoothGattCallback from being executed multiple times at a time

  12. 12

    How to prevent Vue from loading the data multiple times?

  13. 13

    ReactJs : How to prevent componentWillUpdate from re-rendering multiple times

  14. 14

    How to prevent function/event from firing multiple times

  15. 15

    How do I grep a exact string from multiple files at the same time?

  16. 16

    Prevent same activity to be started multiple times

  17. 17

    prevent same fragment multiple times in backstack

  18. 18

    Electron prevent opening same window multiple times

  19. 19

    JS: How to match one capture group multiple times in the same string?

  20. 20

    How can I iteratively partition the same string multiple times?

  21. 21

    How to declare the same string value multiple times inside an array?

  22. 22

    Bash: How can I grep a line for multiple instances of the same string?

  23. 23

    How do I read multiple times from same line in stdin?

  24. 24

    How to read multiple times from same io.Reader

  25. 25

    How to get same key multiple times from json response?

  26. 26

    Prevent eventListener from firing multiple times

  27. 27

    Javascript - prevent function from executing multiple times

  28. 28

    Prevent Form from opening multiple times

  29. 29

    Printing characters(with delay) on the same widget multiple times in Tkinter

HotTag

Archive