Hi Amanda,
This should work for you. It just reads the input file one line at a time and prints that line to an output file. If it hits a new "section", it makes a new output file named by that section.
fidIn = fopen('inputFile.txt','r');
oldFirstChars = 'somethingtostart';
fidOut = [];
while 1
tline = fgetl(fidIn);
if ~ischar(tline), break, end
newFirstChars = regexp(tline, '\d+','match','once');
if ~strcmp(oldFirstChars, newFirstChars)
if ~isempty(fidOut)
fclose(fidOut);
end
fidOut = fopen(['outputFile' newFirstChars '.txt'],'w');
oldFirstChars = newFirstChars;
end
fprintf(fidOut, '%s\r\n',tline);
end
fclose(fidIn);
fclose(fidOut);
Best Answer