Quote:
Originally Posted by ./hari.sh
Hi all
Can anybody suggest me, how to get the count of digits in a word
I tried
Code:
WORD=abcd1234
echo $WORD | grep -oE [[:digit:]] | wc -l
4
It works in bash command line, but not in scripts
|
It seems you're on
GNU system, so you probably have
bash >= 3 and you could try something like this:
Code:
$ WORD=abcd1234
$ [[ $WORD =~ [0-9]{5}$ ]] && echo OK || echo KO
KO
$ WORD=abcd12345
$ [[ $WORD =~ [0-9]{5}$ ]] && echo OK || echo KO
OK