Solved

Find Sentence

Posted on 2014-03-02
1
251 Views
Last Modified: 2014-03-02
I have two files. One is a large block of text. It has paragraphs, where sentences wrap from line to line. The other file is just a bunch of sentences, one per line. I would like to open the file that has once sentence per line, and see if any of the sentences exist in the large text file. I have to imagine that this would be done in a sort of for each loop. Probably while reading the big text file into an array? I would like for it to echo the sentences that it finds in the big text file.

I have found:
for (@lines) {
  print if /keyword/;
}

Open in new window


Which seems to do what I want but I am not certain how to iterate the for the /keyword/ section, using each line of the other file.
0
Comment
Question by:stakor
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39898281
#!/usr/bin/perl
use strict;
use warnings;
open P,"<One" or die $!;
my $p=do{local $/;<P>};
close P;
open S,"<other" or die $!;
$p =~ s/\s+/ /g;
while( <S> ){
  my $r=$_;
  $r =~ s/\s+/ /g;
  print if index($p,$r)>=0;
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now