Record 1 has
five states? Why?
For something open-ended I think I'd write it like a parser.
Assume that "read" works on individual characters and first looks at a temporary variable so that you can "put a character back" (i.e. into that variable) if you don't like it. Different languages or data representations need different amounts of backtracking.
You're at the start of the file, expect a well-formed record.
You're at the start of a record, discard whitespace and expect # (anything else is an error i.e. report back that you don't have a well-formed record).
While you've got digits save them temporarily as a number. When you've not got a digit "put it back".
Expect . anything else is an error.
Discard whitespace.
Save everything until / as the record name.
Expect a sequence of content lines.
If blank or EOF you're at the end of the record.
Otherwise discard whitespace and expect a number (as above), incrementing the count of lines in that record.
And so on.
So your parser becomes something like
repeat
until not wellFormedRecord();
and wellFormedReord() is defined like
function wellFormedRecord(): boolean;
begin
result := true;
if not wellFormedHeaderLine() then
exit(false);
if not wellFormedContentSequence() then
exit(false)
end;
And so on. You will find looking at
https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form will help, basically you write a function for every rule in the grammar and in cases where you have multiple possibilities you expect one of a number of functions to return success otherwise you report an error.
If you were parsing something like Pascal, C, HTML or an XML-based data file you would find lots of tools to help. But when you've got a completely custom format you will find that being able to write a custom parser with moderate proficiency is a useful skill.
Alternatively you could read entire lines and process each as a regex (regular expression) deciding whether it was a header, content line and so on, but I really don't recommend trying that.
MarkMLl