How to read only text from a big data?

I have a huge data file (.txt) with some text and numeric data. It is organized as follows:
Text1 ....
Numeric data (m1xn1)
Text2
Numeric data (m2xn2)
Text3
Numeric Data (m3xn3).....
so on...
I just want to read the data file and display Text1, Text2, Text3 etc . on the command window. How can do that? I tried the following code which read only the first line. Is it possible to modify the code to read all the text line by line? All these text has 'Scan' in it. So may be by searching for lines with 'Scan' and display in the command window. I dont know how to code this.
file = 'C:\Users\Documents\21072016_Exp_A.txt';
[fid, message] = fopen(file,'rt');
tline = fgets(fid);
disp(tline)
fclose(fid);

2 Comments

per isakson
per isakson on 18 Sep 2017
Edited: per isakson on 18 Sep 2017
How large is the file compared to the primary memory?
around 500MB

Sign in to comment.

 Accepted Answer

S = fileread(file);
S = regexp(S, '^\s*[+0123456789-].*$','match','lineanchors', 'dotexceptnewline') ;
fprintf('%s\n', S{:}) ;

5 Comments

The assumption here is that no "text" line starts with + or - or a digit
aneps
aneps on 18 Sep 2017
Edited: aneps on 18 Sep 2017
This is displaying all the numeric data instead of text on the command window! I want to display only text (Text1, Text2, etc.) on the command window. All thes text include the string 'Scan'. May by searching lines having the string 'Scan' and display them. Is it possible to make a code to do this task?
In 99% of the cases people want to keep the numeric data. To catch the text try
S = fileread(file);
S = regexp(S, '^.*Scan.*$','match','lineanchors', 'dotexceptnewline') ;
fprintf('%s\n', S{:}) ;
Thank you.. This worked.. Yes, I also want to keep the numeric data. But the texts in the data file has important information. I need to know those when I process several data files. That is why I just want to display those in the command window.
In my code put an ^ right after the [

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!