Issue
Got a file like:
$ cat file1.txt
123456
1234n5678nn
12n4567890123
123n56n89n1n
I am trying:
grep -E 'n{3,}' file1.txt
to get only lines that have more than two occurrences of n
in them (do not have to be consecutive) but this did not work. The output I want is:
1234n5678nn
123n56n89n1n
Please note I have to do this with grep
or egrep
only - cannot use sed
or awk
.
Solution
You could do it like this:
grep -E '(n.*){3,}' file1.txt
Or using the method you've already tested and worked fine:
grep -E 'n.*n.*n' file1.txt
Answered By - Rfroes87