Re: question on grep

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux