Counting characters with unix utilities

R Chandrasekar mickey at ncst.ernet.in
Thu Oct 4 23:02:04 AEST 1990


In article <4002 at umbc3.UMBC.EDU> rouben at math9.math.umbc.edu () writes:
>How can I count the number of occurrences of a given character in a file?
>...
>The closest  I have come to this is the following construction:
>
>cat file | tr -c 'A' '' | wc -c

Try:

    tr -dc 'A' < file | wc -c

tr -dc 'A'
  deletes all chars which are in the complement set of 'A'.
Voila etc etc! Works, but is a 'sumb' way to count chars. Is there
a better way?

>
>Rouben Rostamian                               Telephone: (301) 455-2458

  -- Chandrasekar



More information about the Comp.unix.questions mailing list