[CentOS] question on grep

Wed Oct 10 20:23:10 UTC 2007
Stephen Harris <lists at spuddy.org>

On Wed, Oct 10, 2007 at 04:10:05PM -0400, Ross S. W. Walker wrote:
> Stephen Harris wrote:
> > 
> > On Wed, Oct 10, 2007 at 04:32:30PM -0300, mups.cp wrote:
> > > A simple one
> > > # echo "jerry jerry" | tr " " "\n" | grep -c jerry
> > > 2
> > 
> > But what about jerry.jerry or jerry/jerry or jerry,jerry or....
> 
> Well he never stated a non-standard field separator, but if that is the case, with awk:

The question wasn't suficiently well defined.  After all, is "jerryjerry"
a count of "1" or "2" ?  :-) :-)

To make the "tr" case more general:
  echo "jerry jerry" | tr -c '[:alnum:]' '\012' | grep -c jerry

Or we could be silly (if each occurance is meant to be counted):
  echo "jerry jerryjerryjerryhellojerry" | sed 's/jerry/\
  jerry/g' | grep -c jerry

-- 

rgds
Stephen