Stephen Harris wrote:
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
True!
Regular expressions sure are fun :-)
I think we've shown enough variations here to give the OP the idea that there are a lot of ways to skin this cat.
-Ross
______________________________________________________________________ This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender and permanently delete the original and any copy or printout thereof.