unixgrep

Grep files containing two or more occurrence of a specific string


I need to find files where a specific string appears twice or more.

For example, for three files:

File 1:

Hello World!

File 2:

Hello World!
Hello !

File 3:

Hello World!
Hello
Hello Again.

--

I want to grep Hello and only get files 2 & 3.


Solution

  • What about this:

    grep -o -c Hello * | awk -F: '{if ($2 > 1){print $1}}'