Reputation: 21
I have a text file that contains multiple headers. It looks like this:
Date,time,*10ms,%%,%%,%%,%%,%%,%%,%%,%%,%%,%%,DETAILS.txt;D;%%;10 11/08/19,13:19:28,03,446,0,545.75,0,6,0,0,0,14,0 11/08/19,13:19:29,05,446,0,549.25,1.9,6,102,1,0,0,0 11/08/19,13:19:30,07,446,0,549.5,1.9,6,102,1,0,0,0 11/08/19,13:19:31,09,446,0,548.75,1.9,6,102,1,0,0,0 . . . . Date,time,*10ms,%%,%%,%%,%%,%%,%%,%%,%%,%%,%%,DETAILS.txt;D;%%;10 11/08/19,13:19:28,03,446,0,545.75,0,6,0,0,0,14,0 11/08/19,13:19:29,05,446,0,549.25,1.9,6,102,1,0,0,0 11/08/19,13:19:30,07,446,0,549.5,1.9,6,102,1,0,0,0 11/08/19,13:19:31,09,446,0,548.75,1.9,6,102,1,0,0,0 . .
and so on...
I would like to write a code that deletes these header-rows and stores the rest of the data to a new file.
Could anyone help with this?
Kind regards,
Tamara
Upvotes: 2
Views: 574
Reputation: 11
readID = fopen('headers.txt', 'r');
writeID = fopen('no_headers.txt', 'w');
while feof(readID) == 0
currLine = fgetl(readID);
if isempty( strfind(currLine, 'Date') )
fprintf(writeID, '%s\n', currLine);
end
end
fclose(readID);
fclose(writeID);
Upvotes: 1
Reputation: 3457
It looks like all the headers are the same, I assume you mean: Date,time,*10ms,%%,%%,%%,%%,%%,%%,%%,%%,%%,%%,DETAILS.txt;D;%%;10
And you wish to use MATLAB, if that's the case, you have to open the file, textscan for that one line and then fgetl to remove it.
No need for regex or anything like that when the line is always the same.
Upvotes: 0