Hi,
I am having some problems in parsing the following data.
Code:
Tom
AGE:25
EDINBURGH
Dick
AGE:24
AMSTERDAM
Harry
AGE:23
BRUSSELS
I am writing a code to generate the following CSV file.
Code:
"AGE:25 EDINBURGH","AGE:24 AMSTERDAM","AGE:23 BRUSSELS"
I started writing the code but I am not able to determine how to get this data because of the following contraints...
a) The data blocks can be in any order
Code -
Code:
function init_array()
{
for (del in feed)
delete feed[del];
i=0;
_Tom_ = 0;
_Dick_ = 0;
_Harry_ = 0;
}
BEGIN { i=0; }
{ record = $0; }
/^$/ { next; }
/Tom/ {
print "Now reading :Tom:";
init_array();
_Tom_ = 1;
next;
}
/Dick/ {
print "Now reading :Dick:";
init_array();
_Dick_ = 1;
next;
}
/Harry/ {
print "Now reading :Harry:";
init_array();
_Harry_ = 1;
next;
}
{
print NR" : "record;
feed[i]=record;
i++;
}
function one()
{
for (j in feed)
ret=ret"\n"feed[j];
return (sprintf("%s",ret));
}
if ( _Tom_ == 1)
Tom=one();
..... (But this doesn't seem right)
END { print Tom,",", Dick,",", Harry; };
Its incomplete, but I am looking for some help.
Kind regards,
indiancosmonaut