Shell Script: Different Method to Find Out Number of Characters in a String

advertisements

_____________________________________________________________________________________________________________________

The Eucharistic Miracles of the World
To count total number of characters in a string
Count total number of
$ mystring="This is my test string"
$ echo "${#mystring}"
22
$ expr length "$mystring"
22

$ echo $mystring|awk '{print length}'
22
$ len=`echo $mystring | wc -c`;echo `expr $len - 1`
22

To count specific characters in sting.
$ grep -o "[s|S]" <<<"$mystring" | wc -l
4
$ grep -o "[ ]" <<<"$mystring" | wc -l
4
$ grep -o "[T|i]" <<<"$mystring" | wc -l
4
$ grep -o "[s|i]" <<<"$mystring" | wc -l

7

_____________________________________________________________________________________________________________________

Website Stats

0 comments:

Post a Comment

Labels

Oracle (629) Script (86) General (77) Unix (47) Blog (23) Technology (19) gadget (6) games (6) Business (3) OCI (3) SQL* Loader (3) Datapump (2)
 

acehints.com Copyright 2011-23 All Rights Reserved | Site Map | Contact | Disclaimer