Search code examples
regexlinuxgrepposix

Find characters that have 2 or more *


If I want to show the lines that have 2 or more times the character this *.

egrep '*{2}' file 

Solution

  • You may use

    grep '\*[^*]*\*' file 
    

    The \*[^*]*\* pattern will match a line that has *, then any 0+ chars other than * and then a *.

    See online demo:

    s="*one
    *two*
    .... *three* and more text here**"
    grep '\*[^*]*\*' <<< "$s"
    

    Output:

    *two*
    .... *three* and more text here**