http://www.perlmonks.org?node_id=167301


in reply to how can i search a text file for a string and print every occurence of that string

Here's a less compicated way to do it.

use strict; my $find = "word or string to find"; open FILE, "<searchfile.txt"; my @line = <FILE>; print "Lined that matched $find\n"; for (@lines) { if ($_ =~ /$find/) { print "$_\n"; } }
However with this will not pick up a match that occurs over multiple lines, and it also is not very fast when munging through huge files.
  • Comment on Re: how can i search a text file for a string and print every occurence of that string
  • Download Code