Can grep show only words that match search pattern?

前端 未结 14 1615
忘掉有多难
忘掉有多难 2020-11-22 14:35

Is there a way to make grep output \"words\" from files that match the search expression?

If I want to find all the instances of, say, \"th\" in a number of files, I

14条回答
  •  囚心锁ツ
    2020-11-22 15:14

    I had a similar problem, looking for grep/pattern regex and the "matched pattern found" as output.

    At the end I used egrep (same regex on grep -e or -G didn't give me the same result of egrep) with the option -o

    so, I think that could be something similar to (I'm NOT a regex Master) :

    egrep -o "the*|this{1}|thoroughly{1}" filename
    

提交回复
热议问题