如何计算 BASH 中字符串中的点数?例如
VAR="s454-da4_sd.fs_84-df.f-sds.a_as_d.a-565sd.dasd"
# Variable VAR contains 5 dots
最佳答案
您可以结合使用 grep
和 wc
命令:
echo "string.with.dots." | grep -o "\." | wc -l
解释:
grep -o # will return only matching symbols line/by/line
wc -l # will count number of lines produced by grep
或者你可以只使用 grep
来达到这个目的:
echo "string.with.dots." | grep -o "\." | grep -c "\."
关于bash - 计算字符串中的点数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11953185/