?
Solved

Parsing text

Posted on 1999-11-13
4
Medium Priority
?
226 Views
Last Modified: 2010-03-05
How can I parse a bunch of words from a text file?

For example I have a file that contains a list of words Ex-
a
the
there
is
etc
and I want to take this file annd remove these words from another text file that conatins the data Ex.
There is a lot of text with the following parsing data that needs to be parsed and only the keywords should remain.

I know I can use the regular expressions to search for a words and replace it with someting else or nothing.  But how do I do it for a list of words?

Any suggestions appreciated?
0
Comment
Question by:sdesar
  • 2
4 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 2205488
perldoc -q "How do I efficiently match many regular expressions at once"
0
 
LVL 3

Accepted Solution

by:
monas earned 200 total points
ID: 2205494
open KW, 'keywordfile';
@kw = map {chop; $_} <KW>;
close KW;


#form RE
$re = join '\b)|(\b', '(\b', @kw, '\b)';

open TXT, 'arg_file';
while (<TXT>){
  s/$re//goi;
  print $_;
}
0
 
LVL 85

Expert Comment

by:ozo
ID: 2205741
#I might prefer
$re = '\b('.(join'|',@kw).')\b';
0
 

Author Comment

by:sdesar
ID: 2228740
Thanks !!
How can I use those keywords and extract only parah. that consists of a particular keyword.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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 …
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 …
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
Suggested Courses

601 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