For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > December 2004 > Re: regexp match large file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: regexp match large file
A Down View

2004-12-27, 8:56 pm

What's the easiest way to match regexp in an entire .txt file against a
set of keywords?

For example, a script that would search an e-mail for the words "hello"
"computer" "johnny" and then return the results?

Sorry if this question is a bit obtuse, I merely exploring an idea...
Thanks.

downview

ioneabu@yahoo.com

2004-12-27, 8:56 pm

You could load the whole file into a string and go from there or, if it
is a big big file, read it in one line at a time.

As far as the matching part, I have asked for help on this topic in the
past so maybe a few links to recent discussion might help:

http://groups-beta.google.com/group...1%26searchnow%3
DSearch+this+group%26&_doneTitle=Back+to+Search&&d#57ac337ed73b655f


http://groups-beta.google.com/group...ch&&d#0caf2c9d4
45a9258

Abigail

2004-12-27, 8:56 pm

A Down View (downview@gmail.com) wrote on MMMMCXXXVI September MCMXCIII
in <URL:news:1104184278.392223.79670@z14g2000cwz.googlegroups.com>:
'' What's the easiest way to match regexp in an entire .txt file against a
'' set of keywords?
''
'' For example, a script that would search an e-mail for the words "hello"
'' "computer" "johnny" and then return the results?
''
'' Sorry if this question is a bit obtuse, I merely exploring an idea...
'' Thanks.


$ grep 'hello|computer|johnny' e.mail

Or:

$ for w in hello computer johnny; do grep $w e.mail; done



Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; kill 15 =>
fork and ($; == getppid and exit or wait) foreach qw /Just another Perl Hacker/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com