Solved

Split this field

Posted on 2001-06-15
5
195 Views
Last Modified: 2010-03-05
Hi all,
I would like to read this text file and store  it on different variable. Each set of data is separated by
##startoffile## and ##endoffile## . I can read this file .. spliting and storing is not done.

The value will be stored as
password= saV9ejDMWuP92.

sub=Hello
msg=Hi there
name=Xavier
date=Fri Jun 15 07:09:57 2001
saV9ejDMWuP92

sub=test
msg=test message1
name=Stefen
date= Fri Jun 15 07:11:32 2001
       
sub=Btech
msg=New Message from usa
name=George
date=Fri Jun 15 07:13:33 2001

sub=hi
msg=hello
name=Alex
date=Fri Jun 15 07:32:56 2001

-------------------------------------------------
Text file starts from here..
-----------------------------------


saV9ejDMWuP92

##startoffile##
Subject::Hello
From::Xavier
Message::
Hi there
Time::  Fri Jun 15 07:09:57 2001
##endoffile##
Subject::test
From::Stefen
Message::
test message1
Time::  Fri Jun 15 07:11:32 2001
##endoffile##
Subject::Btech
From::George
Message::
New Message from usa
Time::  Fri Jun 15 07:13:33 2001
##endoffile##
Subject::hi
From::Alex
Message::
hello
Time::  Fri Jun 15 07:32:56 2001
##endoffile##

------------------------

Pls provide the solution as early as possible.
Thanks
0
Comment
Question by:r_kar
[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
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 70 total points
ID: 6195644
didn't seem too easy...
but try this script:



open FILE, "parse.txt";
my $file='';
my @f=<FILE>;
foreach(@f){
$file.=$_;
}

$file=~/([^ \t\n\r]+)[\n\r\t ]*##startoffile##/s;
$pw=$1;
while($file=~/(?:##startoffile##)?([^#]+)##endoffile##/sg){
push @msgs, $1;
}
foreach(@msgs)
{
while($_=~/([^:]+)::\n?([^\n]+)\n/sg){
$v=$1;
chomp($l=$2);
$l=~s/\n//;
push( @{ $mail{$v} }, $l)
}}

print "password: $pw\n\n";

for($i=0;$i<$#msgs;$i++)
{
foreach(sort keys %mail)
{
print $_ . " = " . $mail{$_}->[$i] . "\n";
}
print "\n\n";
}



Bob
0
 

Author Comment

by:r_kar
ID: 6209368
bebonham,
Excellent performance.
Thanks a lot
0
 

Author Comment

by:r_kar
ID: 6209373
bebonham,
Excellent performance.
Thanks a lot
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6212449
hey, glad to be of help!

your welcome.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6212450
hey, glad to be of help!

your welcome.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

717 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