Can grep show only words that match search pattern?

前端 未结 14 1802
忘掉有多难
忘掉有多难 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:28

    Try grep -o

    grep -oh "\w*th\w*" *
    

    Edit: matching from Phil's comment

    From the docs:

    -h, --no-filename
        Suppress the prefixing of file names on output. This is the default
        when there is only  one  file  (or only standard input) to search.
    -o, --only-matching
        Print  only  the matched (non-empty) parts of a matching line,
        with each such part on a separate output line.
    

提交回复
热议问题