in reply to find a string and count of its occurence in a text file

Do not overlook any opportunity for using all of the tools that may be available to you. For instance, this particular requirement might be easily met by awk, without the use of any Perl programming at all!

And if that be the case... "cool!"

Replies are listed 'Best First'.
Re^2: find a string and count of its occurence in a text file
by dwu (Monk) on Nov 15, 2007 at 03:56 UTC

    For instance, this particular requirement might be easily met by awk

    In fact, there's a general Linux recipe for just these things, generally introduced right around the time whatever book/tute/etc. decides to introduce pipes:

    $ egrep ^abc <filename> | wc -l

    Disclaim: This wouldn't work if OP had, say, wanted to find the total number of occurrences of a given string that happened to occur more than once per line in data; as it is, OP doesn't (or at least, data doesn't contain the sort of case that would prevent this working) :)