extract words from txt using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract words from txt using perl
# 1  
Old 12-17-2009
extract words from txt using perl

Hi,
i will deal with txt file and i want to use perl to extract number of words from this txt
ex :if the txt file is a story which contains person names and iwant to extract these names and there is something else that these names which i want perl to extract must match the words (person names)
wich are saved in a mysql database.
now i need perl to deal with database get person names from its first column and compare it word by word with the txt file words till it find all the matches using perl.
The output should be txt file contains the person names that match the database words and already exist in the txt file. unfortunately i am beginner in this language and i don't know how to deal with this problem.
# 2  
Old 12-17-2009
If you are a beginner, then the problem, in its entirety, may look daunting. Break it up into small pieces and work on them individually.

(1) First, connect to the MySQL database from Perl using DBI.
(2) Run the query and store the results - either in a file or better still, in a hash (if memory isn't an issue or if there aren't too many words).
(3) Next, open the text file and loop through each word.
(4) Check if the word is a hash key. If it is, print the word to stdout or to a file.

Hope these suggestions will at least get you started.

tyler_durden
# 3  
Old 12-18-2009
Thanks very much now the task begin to be easy but sorry i will have questions while i am going ahead with that.( as really it is the first time for me to use perl)

About the connection with mysql this is the perl function as i wrote it in a notebad and saved it begin.pl and i went to command prompt and i wrote

C:\Perl\eg\begin.pl

the code in the begin.pl is

PHP Code:
#!/usr/bin/perl
BEGIN {
# PERL MODULES WE WILL BE USING
use DBI;
use 
DBD::mysql;
$dbh DBI->connect('DBI:mysql:db1''person') || die "Could not connect to database: $DBI::errstr";}
# (insert query examples here...)
$sth $dbh->prepare('SELECT describtion FROM protein_names where gene_name=AMELY');
$sth->execute();
$result $sth->fetchrow_hashref();
print 
"Value returned: $result->{description}\n";
 
end{
$dbh->disconnect();


but the code don't work and when i type the path

C:\Perl\eg\begin.pl in the command prompt the answer is :
is not recognized as internal or external command

Note: i made sure that the perl has the modules which i used above
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. UNIX for Beginners Questions & Answers

Extract Bracketed Words

Hi there, Unixers I need to extract ALL the words from a text which aresurrounded by square brackets. I am using this piece of code sed 's/.*\.*/\1/g' inputfile > outputfile but I only get one word for every paragraph, why? Please use CODE tags as required by forum rules! (7 Replies)
Discussion started by: eldeingles
7 Replies

3. Shell Programming and Scripting

Extract words before and after a certain word.

I have a sample text file with file name: sample.txt The text file has the following text. this is an example text where we have to extract certain words before and after certain word these words can be used later to get more information I want to extract n (a constant) words before and... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

4. Shell Programming and Scripting

Extract the filename and write to .txt

I'm new to this forum and also to UNIX scripting. I need a command to extract the filename from the path and write to .txt file. Thanks in advance for your guidance. (23 Replies)
Discussion started by: Ram Kumar_BE
23 Replies

5. Shell Programming and Scripting

grep words from txt

Queue on node in domain description : type : local max message len : 104857600 max queue depth : 5000 queue depth max event : enabled persistent msgs : yes backout threshold : 0 msg delivery seq :... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

6. Shell Programming and Scripting

Extract words from a pipe

Hello, Currently, I have this output from my application : ------------------------------------------------- Log viewer/Tmp1 (Jun 29 2011 09:48) ------------------------------------------------- BlalbalbaBlalbalba..Blalbalba..Blalbalba..Blalbalba..Blalbalba..Blalbalba..Blalbalba....... (3 Replies)
Discussion started by: acidoangel
3 Replies

7. UNIX for Dummies Questions & Answers

Extract words to new file

Hi there, Unix Gurus Working with big listings of english sentences for my pupils, of the type: 1. If the boss's son had been , someone would have asked for money by now. 2. Look, I haven't a crime, so why can't you let me go? .... I wondered how to extract the words between brackets in... (7 Replies)
Discussion started by: eldeingles
7 Replies

8. UNIX for Dummies Questions & Answers

Extract numbers from .txt file

I need to extract all the p-value numbers and the rho numbers from a .txt file and write them as coma separated values in a new file. Ideally I would get two files in the end, one for p- values and one for rho. Any suggestions? I appreciate your help!!! The .txt file looks essentially like this... (5 Replies)
Discussion started by: eggali
5 Replies

9. Shell Programming and Scripting

Extract from txt file

I have data as follow in the txt file. I want to skip line starting with '#' sign. #command program abc defmt exp refmt ... ... I want to store abc exp .... in a array. I want to store defmt refmt in a array I need command to read each line in the file. I need... (6 Replies)
Discussion started by: ekb
6 Replies

10. UNIX for Advanced & Expert Users

How to extract two words at the same time.

Hi, Can anyone please let me know, how to extract two lines at the same time. In specific,I have a file containing list of devices, such as router1 and switch2 below. I want to get all the lines which has "#" and all the lines which has "down" router1#sh ip int br Interface ... (6 Replies)
Discussion started by: Aejaz
6 Replies
Login or Register to Ask a Question