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

i read that using grep is not advisable for huge files

Someone lied to you.

You probably want something like this:

while ( <FILE> ) { print if 'abc' eq ( split /:/ )[ 0 ]; }

Or possibly this:

while ( <FILE> ) { print if /^abc:/; }

Replies are listed 'Best First'.
Re^2: find a string and count of its occurence in a text file
by dwu (Monk) on Nov 14, 2007 at 05:53 UTC
    And to chuck in an (incredibly primitive) idea for a line count as well:
    _data.txt_ abc:AB CD:100 def:DE FG:101 ghi:GH IJ:102 abc:AB CD:100 ghi:GH IJ:103 my $count; while ( <FILE> ) { print if /^abc:/; $count++ if /^abc/; } print "Matched $count times\n"; _output_ abc:AB CD:100 abc:AB CD:100 Matched 2 times
    Update: I'm silly; added condition for incrementing $count.
Re^2: find a string and count of its occurence in a text file
by cdarke (Prior) on Nov 14, 2007 at 09:27 UTC
    i read that using grep is not advisable for huge files

    Someone lied to you.


    Maybe lied is a bit strong, they we probably thinking of this:
    grep /fred/,<FILE>;
    which loads the entire file into memory (or at least, tries to).
      I thought he meant grep(1) instead of perldoc -f grep    :-)