Ross S. W. Walker wrote: > > mups.cp wrote: > > > > A simple one > > # echo "jerry jerry" | tr " " "\n" | grep -c jerry > > 2 > > > > The perl seems more general. > > > To add yet another variation: > > echo "jerry jerry" | awk 'BEGIN {RS=FS} {/jerry/ jerry++} END > {print jerry}' That should have been: echo "jerry jerry" | awk 'BEGIN{RS=FS} /^jerry$/ {jerry++} END{print jerry}' -Ross > > On 10/10/07, Andy Harrison <aharrison@xxxxxxxxx> wrote: > > > -----BEGIN PGP SIGNED MESSAGE----- > > > Hash: SHA1 > > > > > > > > > > > > On 10/10/07, Jerry Geis wrote: > > > > Is there a command line option on grep that says > > > > count ALL occurances on a line not just the first one??? > > > > > > > > echo "jerry jerry" | grep -c jerry > > > > > > > > > > Grep can just count the number of lines with occurrences not the > > > number of them. You can do it in perl though. > > > > > > > > > # echo "jerry jerry" | perl -lane '$count = grep $_ =~ > m/jerry/, @F; > > > print $count' > > > 2 > > > > > > - -- > > > Andy Harrison > > > public key: 0x67518262 > > > -----BEGIN PGP SIGNATURE----- > > > Version: GnuPG v1.4.5 (GNU/Linux) > > > Comment: http://firegpg.tuxfamily.org > > > > > > iD8DBQFHDSMVNTm8fWdRgmIRAsDIAJ9KiT+6vuaWjwezW+nd5YuHVRCJ6wCfQIoq > > > Wat5Wo5Kmsup6XnJ06RVaVo= > > > =WlD0 > > > -----END PGP SIGNATURE----- > > > _______________________________________________ > > > CentOS mailing list > > > CentOS@xxxxxxxxxx > > > http://lists.centos.org/mailman/listinfo/centos > > > > > _______________________________________________ > > CentOS mailing list > > CentOS@xxxxxxxxxx > > http://lists.centos.org/mailman/listinfo/centos > > > > ______________________________________________________________________ > 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. > > _______________________________________________ > CentOS mailing list > CentOS@xxxxxxxxxx > http://lists.centos.org/mailman/listinfo/centos > ______________________________________________________________________ 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. _______________________________________________ CentOS mailing list CentOS@xxxxxxxxxx http://lists.centos.org/mailman/listinfo/centos