[CentOS] question on grep

Ross S. W. Walker rwalker at medallion.com
Wed Oct 10 20:10:05 UTC 2007


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:

echo "jerry,jerry-jerry jerry" | awk 'BEGIN{RS="[^[:alnum:]]"} /^jerry$/ {jerry++} END{print jerry}'

That'll separate records by any non-alphanumeric.

(I had messed up the comparison on my first post)

-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.




More information about the CentOS mailing list