Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Searching large file Message-ID: <9338@jpl-devvax.JPL.NASA.GOV> Date: 30 Aug 90 00:34:02 GMT References: <1990Aug29.003742.16051@pegasus.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 20 In article <1990Aug29.003742.16051@pegasus.com> richard@pegasus.com (Richard Foulk) writes: : I need to search a large file or two for a text string. What is the : fastest way to search a large file for the first occurance of some : random string and return its location? Something like this, assuming you feed it real filenames. As a filter, you'd have to keep track of position yourself. #!/usr/bin/perl $text = shift; $text =~ s/(\W)/\\$1/g; eval <) { print("\$ARGV: pos ", tell(ARGV)-length, "\\n"),close ARGV if /$text/; } EOF In a little while I'll have the o modifier be as fast, but not yet. Larry