1848296 Members
7503 Online
104024 Solutions
New Discussion

Re: PERL Question

 
Scott_323
New Member

PERL Question

I am trying to extract a piece of code from a number of files in a directory.

It looks a little something like this:

STATUS: CLOSED

ABSTRACT:

THIS EFFORT INVOLVES RESEARCHING THE STATE OF THE ART TRACKING ASSET
TRACKING TECHNOLOGIES WITH SPECIAL EMPHASIS ON REUSABLE CONTAINERS/PACKING
AND PACKAGING SUPPLIES.

CONTRACT SPECIALIST: CHUCK

There are a series of other fields in the file. I have split the values on the left and right side of the colon and place them into a hash (each file is a unique number for the key of the hash). I am having trouble figuring out the best way to extract everything from the right side of the ABSTRACT colon down to the beginning of CONTRACT SPECIALIST. Eventually these values will go into a Oracle database. Any help would be greatly appreciated.

Thanks

Scott
3 REPLIES 3
Rodney Hills
Honored Contributor

Re: PERL Question

In this type of situation you need to determine when the block of text begins and when it ends. It begins after "ABSTRACT" and ends prior to "CONTRACT SPECIALIST".

A program reading through the file might set a flag to indicate when it is accumulating the lines for the ABSTRACT and when the end of the ABSTRACT occurs, put those lines into your hash table.

I hope I understood what your question...

-- Rod Hills
There be dragons...
H.Merijn Brand (procura
Honored Contributor

Re: PERL Question

lt09:/tmp 119 > perl -ne's/^(\w.*?)://and$k=$1;$h{$k}.=$_}END{print"[[$_]]\n--$h{$_}"for keys%h' file
[[ABSTRACT]]
--

THIS EFFORT INVOLVES RESEARCHING THE STATE OF THE ART TRACKING ASSET
TRACKING TECHNOLOGIES WITH SPECIAL EMPHASIS ON REUSABLE CONTAINERS/PACKING
AND PACKAGING SUPPLIES.

[[STATUS]]
-- CLOSED

[[CONTRACT SPECIALIST]]
-- CHUCK

lt09:/tmp 120 >


Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Geetha.R
Occasional Advisor

Re: PERL Question

Scott,
You can try the following PERL script.
In the script, replace with your filename within codes.

%hashArr;
open(FILE,)||die("Cannot open file");
$line = ;
while(defined($line)){

if(length($line)>1)
{

if(($line) =~ /:/)
{
($key,$val)=split(/:/,$line);
}
else
{
$val=$line;
}


}
if(length($key)>1 && length($val) >1)
{
$hashArr{$key}=$val;

}
$line=;
}
foreach $key (keys %hashArr) {
print "\$hashArr{$key} = $hashArr{$key}\n";
}


This script will store the data in a Hash (key,value pair).
After doing this, you can connect to Oracle & store the values.
Hope this helps you.

Geetha