Count Substring Occurrences

Count how many times a substring appears in a string (non-overlapping).

Code

General
echo "$str" | grep -o "$substring" | wc -l | tr -d ' '

Parameters

The string to search in

The substring to count

Server

More Bash Snippets