I need to efficiently count every character of an arbitrary file by its character CLASS (as defined by the BASH man page); i.e.
[[:alnum:]], [[:alpha:]], [[:ascii:]], [[:blank:]], [[:cntrl:]], [[:digit:]], [[:graph:]], [[:lower:]], [[:print:]], [[:punct:]], [[:space:]], [[:upper:]], [[:word:]] and [[:xdigit:]]
Once the file is processed, display on a single line the resulting counts for each, even when zero.
Web searches have not been fruitful in finding something along these lines.
The arbitrary file (
/tmp/f1.txt) will contain a variety of diverse text/data.
I am not looking to process ELF binaries nor UniCode (or any form of multi-byte) content.
I am not concerned about line count (
LF), only fixated on accumulating a count of each 'character' in the target file by the above classes.
I intend for this to end up as a standard
function() in a larger bash script. Bash/sed/awk and the like are desired; while perl/python/ruby not so much.
Sample data files could be:
Zero bytes, i.e. no content at all.
A single character
A single word
Multiple words separated by whitespace
Multiple lines interspersed with whitespace and/or CarriageReturns and/or LineFeeds.
For multiline files there might not be a
LFto signify the end of the last line (yet all characters should still be counted).