Can grep show only words that match search pattern?

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

    Just awk, no need combination of tools.

    # awk '{for(i=1;i<=NF;i++){if($i~/^th/){print $i}}}' file
    the
    the
    the
    this
    thoroughly
    

提交回复
热议问题