Solved

Find Sentence

Posted on 2014-03-02
1
246 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

20 Experts available now in Live!

Get 1:1 Help Now