Xref: utzoo comp.unix.questions:25826 comp.unix.shell:332 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!srcsip!msi-s0.msi.umn.edu!haberman From: haberman@msi.umn.edu (Joe Habermann) Newsgroups: comp.unix.questions,comp.unix.shell Subject: Re: Counting characters with unix utilities Message-ID: <1990Sep28.173033.292@msi.umn.edu> Date: 28 Sep 90 17:30:33 GMT References: <4002@umbc3.UMBC.EDU> <939@hls0.hls.oz> Organization: Minnesota Supercomputer Institute Lines: 14 george@hls0.hls.oz (George Turczynski) writes: >OK, try this: > awk -F'A' '{ sum+= (NF-1) } END { print sum }' file This is close. Doesn't seem to work when the number of matches = 0, though. In that case NF = 0 and the awk will return -1. How about: awk -F'A' '{ if (NF > 0) sum += (NF-1) } END { print sum }' file Joe Habermann / haberman@msi.umn.edu