Search code examples
linuxstringshelluppercase

Count uppercase characters in a word


I need to count how many uppercase letters there are in a word. How can I do this?


Solution

  • I like tr for this:

    echo "$word" | tr -dc A-Z | wc -c
    

    simply delete all characters that are not uppercase and count what is left.

    You might prefer tr -dc [:upper:], but I find A-Z easier to use.