Search code examples
bashfilelinescounting

BASH - quickly determine the number of lines in a file that start with a Uppercase


How can I quickly determine the number of lines in a file that start with a Uppercase?

I think with regex this would be [A-Z]*), but I don't want to "read line" ... something more faster.


Solution

  • Your best option if you don't want to use a read loop would be to use grep, with the -c switch which counts matching lines, like this:

    grep -c ^[A-Z] the_file.txt