[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file
From: |
Dan Sebald |
Subject: |
[Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present |
Date: |
Tue, 16 Jan 2018 04:41:59 -0500 (EST) |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0 |
Follow-up Comment #4, bug #52892 (project octave):
There is another difference between these two attached data files. The EOL
character for cruise_params_with_empty_lines.cfg is <0A> LF while the EOL
characters for cruise_params_no_empty_lines.cfg is <0D><0A> CR+LF. For me,
the following work:
octave:33>
[a,b]=textread('cruise_params_with_empty_lines.cfg','%s%s','Delimiter','=','CommentStyle','#');
octave:34> a{1}
ans = working_directory
octave:35> b{1}
ans = .
octave:36> a{end}
ans = beam2earth_bad_down_beam
octave:37> b{end}
ans = nan
octave:38>
octave:38>
octave:38>
[a,b]=textread('cruise_params_no_empty_lines.cfg','%s%s','Delimiter','=','CommentStyle','#',"endofline","\n");
octave:39> a{1}
ans = working_directory
octave:40> b{1}
ans = .
octave:41> a{end}
ans = beam2earth_bad_down_beam
octave:42> b{end}
ans = nan
That is, if I tell textread that the "endofline" is "\n" (the LF or CR+LF)
then the file reads fine. I suppose the CR before the LF gets treated as
whitespace and is ignored.
The following doesn't quite work:
octave:43>
[a,b]=textread('cruise_params_no_empty_lines.cfg','%s%s','Delimiter','=','CommentStyle','#',"endofline","\r");
octave:44> a{1}
ans = working_directory
octave:45> b{1}
ans = .
octave:46> a{end}
ans =
octave:47> b{end}
ans =
octave:48> [length(a) length(b)]
ans =
123 123
There's an extra entry at the end because after the last CR is still a LF and
that gets treated as another line.
Anyway, could it be that the bug here is simply that textread() is not
auto-detecting CR+LF when the documentation suggests that it should?
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?52892>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Pedro Pena, 2018/01/14
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Dan Sebald, 2018/01/15
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Philip Nienhuis, 2018/01/15
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Philip Nienhuis, 2018/01/15
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present,
Dan Sebald <=
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Pedro Pena, 2018/01/16
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Philip Nienhuis, 2018/01/16
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Pedro Pena, 2018/01/16
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Dan Sebald, 2018/01/17
- [Octave-bug-tracker] [bug #52892] textread incorrectly reads a text file when empty lines are present, Pedro Pena, 2018/01/17