Xref: utzoo comp.unix.questions:25973 comp.unix.shell:430 Path: utzoo!attcan!uunet!shakti!mickey From: mickey@ncst.ernet.in (R Chandrasekar) Newsgroups: comp.unix.questions,comp.unix.shell Subject: Re: Counting characters with unix utilities Message-ID: <986@shakti.ncst.ernet.in> Date: 4 Oct 90 13:02:04 GMT References: <4002@umbc3.UMBC.EDU> Reply-To: mickey@shakti (R Chandrasekar) Followup-To: comp.unix.questions Organization: National Centre for Software Technology, Bombay, INDIA Lines: 20 In article <4002@umbc3.UMBC.EDU> rouben@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