There are anomalies in the file that keep this approach from working correctly.
My attempt —
type('sample_input.txt')
Hello_Message.pdf
2341234342 3214234 ert
2341234342 3214234 abc
2341234342 3214234
Some_ting
23453425
Blah_bleh
Sadf_5
Ouch 4
TEST
Asdff: sdf_sdf
Is_sdf: asdf
IS_ssg: sadf
NJ_T: adfgh
Some_data_: 4 sadf sadf asdf 45676578675 sdaf sadf asdf asdf sadf 4365436546 sdfdsf 0 sadfsdffds 0 <Item> toaster</Item> dsfasdf sadfdsakfdsfklj sdafsdafdsa fds
&&&
Hello_Message.txt
2341234342 3214234 ert
2341234342 3214234 abc
2341234342 3214234
Some_ting
23453425
Blah_bleh
Sadf_5
Ouch 4
TEST
Asdff: sdf_sdf
Is_sdf: asdf
IS_ssg: sadf
NJ_T: adfgh
Some_data_: 4 sadf sadf asdf 45676578675 sdaf sadf asdf asdf sadf 4365436546 sdfdsf 0 sadfsdffds 0 <Item> thisdata</Item> dsfasdf sadfdsakfdsfklj sdafsdafdsa fds
&&&
Bye_Message.pdf
2341234342 3214234 ert
2341234342 3214234 abc
2341234342 3214234
Some_ting
23453425
Blah_bleh
Sadf_5
Ouch 4
TEST
Asdff: sdf_sdf
Is_sdf: asdf
IS_ssg: sadf
NJ_T: adfgh
Some_data_: 4 sadf sadf asdf 45676578675 sdaf sadf asdf asdf sadf 4365436546 sdfdsf 0 sadfsdffds 0 <Item> sadfsdfdsfasdf</Item> dsfasdf sadfdsakfdsfklj sdafsdafdsa fds
&&&
Hello_Message.pdf
2341234342 3214234 ert
2341234342 3214234 abc
2341234342 3214234
Some_ting
23453425
Blah_bleh
Sadf_5
Ouch 4
TEST
Asdff: sdf_sdf
Is_sdf: asdf
IS_ssg: sadf
NJ_T: adfgh
Some_data_: 4 sadf sadf asdf 45676578675 sdaf sadf asdf asdf sadf 4365436546 sdfdsf 0 sadfsdffds 0 <Item> iron </Item> dsfasdf sadfdsakfdsfklj sdafsdafdsa fds\
&&&
fidi = fopen('sample_input.txt','rt')
fidi = 3
k = 1;
while ~feof(fidi)
Line{k,:} = fgetl(fidi);
k = k+1;
end
fclose(fidi);
k
k = 92
Line
Line = 91×1 cell array
{0×0 char }
{'Hello_Message.pdf' }
{'2341234342 3214234 ert' }
{'2341234342 3214234 abc' }
{'2341234342 3214234' }
{'Some_ting' }
{'23453425' }
{'Blah_bleh' }
{'Sadf_5' }
{'Ouch 4' }
{'TEST' }
{' ' }
{' ' }
{' ' }
{'Asdff: sdf_sdf' }
{'Is_sdf: asdf' }
{'IS_ssg: sadf' }
{'NJ_T: adfgh' }
{0×0 char }
{'Some_data_: 4 sadf sadf asdf 45676578675 sdaf sadf asdf asdf sadf 4365436546 sdfdsf 0 sadfsdffds 0 <Item> toaster</Item> dsfasdf sadfdsakfdsfklj sdafsdafdsa fds'}
{'&&&' }
{0×0 char }
{0×0 char }
{0×0 char }
{'Hello_Message.txt' }
{'2341234342 3214234 ert' }
{'2341234342 3214234 abc' }
{'2341234342 3214234' }
{'Some_ting' }
{'23453425' }
for k1 = 1:k-1
if ~isempty(Line{k1,:})
if strmatch(Line{k1,:},'Hello_Message.pdf')
% Start(k1) = 1
sprintf('Start = %2d',k1)
end
if strmatch(Line{k1}, '&&&')
% End(k1) = 1;
sprintf('End = %2d',k1)
end
end
end
ans = 'Start = 2'
ans = 'End = 21'
ans = 'End = 44'
ans = 'End = 65'
ans = 'Start = 72'
ans = 'End = 91'
.