I think the following annotated script gives a simple way of executing the
task you want.
It duplicates your data, modifies you tags list and applies the method to
test script.
How to move it to your files application is mentioned at the end.
I hope this works for you.
textfile3=: 0 : 0
Start of event 1 crlftb
Some text crlftb
Some more text crlftb
param1 = 12345 crlftb
param2 = NONE crlftb
some comments crlftb
param3 = hello world crlftb
more comments crlftb
param4 = 120.45 crlftb
param6 = Test y crlftb
End of stuff crlftb
Start of event 2 crlftb
Some text crlftb
Some different text crlftb
param1 = 34567 crlftb
param3 = hello bob crlftb
param4 = 32.89 crlftb
comments and more comments crlftb
param5 - zero one crlftb
param 6 = Test z crlftb
Second end crlftb
Start of event 3 crlftb
param5 = two three crlftb
Start of event 4 crlftb
stuff crlftb
param1 = 6789 crlftb
param2 = SOME crlftb
end crlftb
)
$ textfile3
Note''
I put the crlftb text on the end of each line, to show the equivalent of
the invisible characters that are actually in the real data.
Here is the string of tag pairs:
)
tags2 =: 'Start';'param1';'param2';'param3';'param5'
NB. New code
txt6 =: <;._2 textfile3 NB. use cut to box each line of data
txt7 =: ;: each txt6 NB. convert each line to J words
p0 =: (tags2 i. {. ) each txt7 NB. find location of each first word in
tags1
notreqd =: (#tags2) = >p0 NB. not a start or param code
txt8 =: (-. notreqd) # txt7 NB. select lines needed for analysis
pp0 =: (-. notreqd) # p0 NB. select
p1 =: I. 0=>pp0 NB. location of all start events
p2 =: (}.p1),#txt8 NB. Location of start of next event - note
treatment at end
p3 =: p2-p1 NB. number of records for each event
pp0,.txt8
NB. To convert this for your use you will need to use a single character
for crlftb
NB. and use it as the defining character for the cut in defn of txt6 above
NB. you will also need to convert the code into a suitable function
NB. but the essential core is I think there
NB. There are probably several ways it can be tidied up and shortened
NB. This is just the sequence of code as I thought of the next step and
tested it
NB. For each event you can now execute
getEventi =: 3 : 0
((y{p2) + i. y{p3) { txt8
)
getEventi 0
getEventi 2
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm