Solved

Find Sentence

Posted on 2014-03-02
1
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

726 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