Solved

Split this field

Posted on 2001-06-15
5
191 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
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…

726 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