Count number of lines between strings in a text file.

3 views (last 30 days)
I have a set of text files with varying amounts of information (i.e. different numbers of lines) in the header. One example file has the following header:
######################################################################
Test File Name: 202204221121
Timestamp: 360
Test Type: EMPTY Valve Selction: BOTH Valve Cycle Time: 2 Test Duration: 360
Pressure Offsets: -0.407,-0.106,-0.190,-0.372,-0.877
Pressure Scaling Data (Upstream down):
InMin,InMax,OutMin,OutMax
16501,18733,675.320,687.525
16101,21331,656.950,686.050
19887,23890,662.13,684.61
15685,20960,656.95,686.05
15276,17316,654.97,666.25
Hawser Scaling Data (lb units)
-1 -.5 -.25 -.125 0 .125 .25 .5 1
27445,33590,36514,37849,39040,40940,42447,45795,50644
27675,33733,36900,37733,39318,40586,41633,44150,49800
29547,33785,36515,37444,41439,41863,43196,45851,52125
######################################################################
How can I programmatically determine the number of lines between the "########" lines? Thanks!

Accepted Answer

Jan
Jan on 26 Apr 2022
S = readlines(filename);
Index = find(startsWith(S, '#'));
Len = diff(Index) - 1 % Length of the blocks

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!