Search This Blog

Shell Script: count the occurences of a specific character

#!/bin/bash

# dot-separated string
str=1.2.3.4.5.6

# prints the number of occurences of dot
echo $str | tr "\." "\n" | wc -l

# prints 5

No comments:

Post a Comment