Counting regex pattern matches in one line using sed or grep?

前端 未结 5 1312
忘掉有多难
忘掉有多难 2021-02-05 02:57

I want to count the number of matches there is on one single line (or all lines as there always will be only one line).

I want to count not just one match per line as in

5条回答
  •  情书的邮戳
    2021-02-05 03:31

    Maybe below:

    echo "123 123 123" | sed "s/123 /123\n/g" | wc -l
    

    ( maybe ugly, but my bash fu is not that great )

提交回复
热议问题