I was wondering how to count the number of a specific character in each line by some text processing utilities?For example, to count  in each line of the following texthello! Thank you!The first line has two, and the second line has 0. Another example is to count ( in each line.
How to count the number of a specific character in each line?
text processing
You can do it with sed and awk:$ sed 's/[^]//g' dat | awk '{ print length }'20Where dat is your example text, sed deletes (for each line) all non- characters and awk prints for each line its size (i.e. length is equivalent to length($0), where $0 denotes the current line).For another character you just have to change the sed expression. For example for ( to:'s/[^(]//g'Update: sed is kind of overkill for the task - tr is sufficient. An equivalent solution with tr is:$ tr -d -c '\n' < dat | awk '{ print length; }'Meaning that tr deletes all characters which are not (-c means complement) in the character set \n.