Counting regex pattern matches in one line using sed or grep? January 4, 2024 by Tarik You could use grep -o then pipe through wc -l: $ echo "123 123 123" | grep -o 123 | wc -l 3