Solved

Split this field

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now