unzip('Sections.zip')
% subdir = 'TCLFiles';
subdir = '';
oldfilename = fullfile(pwd,subdir,'Sections.tcl');
newfilename = fullfile(pwd,subdir,'Sections_fixed.tcl');
% original file contents, for reference
type(oldfilename)
# Sections.tcl
# Section "ElasticDefault": secTag E A Iz Iy G J <alphaY> <alphaZ>
section Elastic 20 +2.900000E+04 +1.800000E+02 +4.860000E+03 +1.500000E+03 +1.115400E+04 +3.916000E+03 +8.333333E-01 +8.333333E-01
# Section "A01Sect": secTag matTag string ... -section secTag
section Aggregator 1 1 P 21 My 21 Mz # Section "A02Sect": secTag matTag string ... -section secTag
section Aggregator 2 2 P 21 My 21 Mz # Section "A03Sect": secTag matTag string ... -section secTag
section Aggregator 3 3 P 21 My 21 Mz # Section "A04Sect": secTag matTag string ... -section secTag
section Aggregator 4 4 P 21 My 21 Mz # Section "A05Sect": secTag matTag string ... -section secTag
section Aggregator 5 5 P 21 My 21 Mz # Section "A06Sect": secTag matTag string ... -section secTag
section Aggregator 6 6 P 21 My 21 Mz # Section "A07Sect": secTag matTag string ... -section secTag
section Aggregator 7 7 P 21 My 21 Mz # Section "A08Sect": secTag matTag string ... -section secTag
section Aggregator 8 8 P 21 My 21 Mz # Section "A09Sect": secTag matTag string ... -section secTag
section Aggregator 9 9 P 21 My 21 Mz # Section "A10Sect": secTag matTag string ... -section secTag
section Aggregator 10 10 P 21 My 21 Mz # Section "A11Sect": secTag matTag string ... -section secTag
section Aggregator 11 11 P 21 My 21 Mz # Section "A12Sect": secTag matTag string ... -section secTag
section Aggregator 12 12 P 21 My 21 Mz # Section "A13Sect": secTag matTag string ... -section secTag
section Aggregator 13 13 P 21 My 21 Mz # Section "A14Sect": secTag matTag string ... -section secTag
section Aggregator 14 14 P 21 My 21 Mz # Section "A15Sect": secTag matTag string ... -section secTag
section Aggregator 15 15 P 21 My 21 Mz # Section "A16Sect": secTag matTag string ... -section secTag
section Aggregator 16 16 P 21 My 21 Mz # Section "A17Sect": secTag matTag string ... -section secTag
section Aggregator 17 17 P 21 My 21 Mz # Section "A18Sect": secTag matTag string ... -section secTag
section Aggregator 18 18 P 21 My 21 Mz # Section "A19Sect": secTag matTag string ... -section secTag
section Aggregator 19 19 P 21 My 21 Mz
% read the original file
str = fileread(oldfilename);
% replace any "#" that is not directly preceded by a newline character
% with a newline followed by a "#". that is, prepend a newline to any #
% that doesn't already have one
str = regexprep(str,'[^\n]#','\n#');
% write the new file
fid = fopen(newfilename,'wt');
fprintf(fid,'%s',str);
fclose(fid);
% check the new file contents (scroll down to see the whole thing)
type(newfilename)
# Sections.tcl
# Section "ElasticDefault": secTag E A Iz Iy G J <alphaY> <alphaZ>
section Elastic 20 +2.900000E+04 +1.800000E+02 +4.860000E+03 +1.500000E+03 +1.115400E+04 +3.916000E+03 +8.333333E-01 +8.333333E-01
# Section "A01Sect": secTag matTag string ... -section secTag
section Aggregator 1 1 P 21 My 21 Mz
# Section "A02Sect": secTag matTag string ... -section secTag
section Aggregator 2 2 P 21 My 21 Mz
# Section "A03Sect": secTag matTag string ... -section secTag
section Aggregator 3 3 P 21 My 21 Mz
# Section "A04Sect": secTag matTag string ... -section secTag
section Aggregator 4 4 P 21 My 21 Mz
# Section "A05Sect": secTag matTag string ... -section secTag
section Aggregator 5 5 P 21 My 21 Mz
# Section "A06Sect": secTag matTag string ... -section secTag
section Aggregator 6 6 P 21 My 21 Mz
# Section "A07Sect": secTag matTag string ... -section secTag
section Aggregator 7 7 P 21 My 21 Mz
# Section "A08Sect": secTag matTag string ... -section secTag
section Aggregator 8 8 P 21 My 21 Mz
# Section "A09Sect": secTag matTag string ... -section secTag
section Aggregator 9 9 P 21 My 21 Mz
# Section "A10Sect": secTag matTag string ... -section secTag
section Aggregator 10 10 P 21 My 21 Mz
# Section "A11Sect": secTag matTag string ... -section secTag
section Aggregator 11 11 P 21 My 21 Mz
# Section "A12Sect": secTag matTag string ... -section secTag
section Aggregator 12 12 P 21 My 21 Mz
# Section "A13Sect": secTag matTag string ... -section secTag
section Aggregator 13 13 P 21 My 21 Mz
# Section "A14Sect": secTag matTag string ... -section secTag
section Aggregator 14 14 P 21 My 21 Mz
# Section "A15Sect": secTag matTag string ... -section secTag
section Aggregator 15 15 P 21 My 21 Mz
# Section "A16Sect": secTag matTag string ... -section secTag
section Aggregator 16 16 P 21 My 21 Mz
# Section "A17Sect": secTag matTag string ... -section secTag
section Aggregator 17 17 P 21 My 21 Mz
# Section "A18Sect": secTag matTag string ... -section secTag
section Aggregator 18 18 P 21 My 21 Mz
# Section "A19Sect": secTag matTag string ... -section secTag
section Aggregator 19 19 P 21 My 21 Mz