I need help figuring out a command that will search a file and display lines that include exactly 2 *.
**, *red*, manche*ste*r*, ***, mache*s*te*rWhat I have so far is:
grep ‘\*.*\*’ filename.txt
But this displays lines that have at least two * but not exactly two. And I can't see to find a way to do that.
You may use
grep '^[^*]*\*[^*]*\*[^*]*$' filename.txt
The regex matches a string that contains exactly two asterisks with any other chars before, after and in-between them.
Pattern details
^ - start of string[^*]* - 0+ chars other than *\* - a *[^*]*\*[^*]* - 0+ chars other than *, a * and again 0+ chars other than *$ - end of string.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With