Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: how can i search a text file for a string and print every occurence of that string

by munchie (Monk)
on May 17, 2002 at 14:01 UTC ( [id://167301]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://167301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found