Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Parsing and emailing

Status
Not open for further replies.

lanlord

MIS
Aug 8, 1999
7
US
I am trying to read chunks of data from a file and emailing parts of it to certain users. I can get the email done but I can't figure out how to get my data out!<br>
I have markers in a flat file to signify the beginning of my data, the username I'll mail to and then a block of data.<br>
<br>
I need to start at ##BEGIN, get the username from #NAME=mailuser, and then pipe all the data between #NAME=mailuser and ##END into a mail message, then start over until I reach the end of my file.<br>
<br>
Any help is welcomed!!<br>
Thanks<br>
<br>
My data file is like so:<br>
<br>
##BEGIN<br>
#NAME=mailuser<br>
<br>
Bunch of data goes here<br>
and here.. this is still mailsuers' data<br>
<br>
##END<br>
##BEGIN<br>
#NAME=mailuser2<br>
<br>
This is where I put mailusers2's data<br>
etc..etc..<br>
<br>
##END
 
Hmmmm.... I've had to do something similar in the past in a previous job, and I don't have the code available. However, IIRC, the following &quot;pseudo-code&quot; is pretty much what I did...<br>
<br>
open file<br>
<br>
while read lines from file<br>
if (line == start pattern && $In_Block_Of_Data == 0)<br>
then<br>
$In_Block_Of_Data = 1<br>
continue # To go on to next line in file.<br>
else<br>
if (line == end pattern && $In_Block_Of_Data == 1)<br>
then<br>
$In_Block_Of_Data = 0<br>
continue # To read next line in file.<br>
else<br>
if ( $In_Block_Of_Data == 1)<br>
then<br>
# Do data processing here.<br>
else<br>
# Some kind of unexpected situation occurred, eg block start with no end.<br>
# Check and deal with it.<br>
endif<br>
endif<br>
endif<br>
end while<br>
<br>
There's probably an easier way of doing this, but this worked for me at the time when I needed it. Hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top