Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find Sentence

Posted on 2014-03-02
1
Medium Priority
?
287 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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

688 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