Reading alphanumeric text file as separate lines
4 views (last 30 days)
Show older comments
Hi,
I am having a text file it contains datasets as wells as tags i want to separate out lines which starts with alphabets.can anyone please help me out with this ?
for example i want to extract out following contents separately from the attached file
*_ _ _ _ _ _strings:
Patient Name: Amalan
Age: 26
Tuesday, May 30, 2017
6:57:26 PM
Reference_spo2:98 185823.869933-1
TAG_time:185726.335642-1_____*_
datasets:
*_503616.000000 477452.000000 1473854.000000 185726.319642
504245.000000 478256.000000 1475081.000000 185726.320641
506299.000000 478958.000000 1475323.000000 185726.321641
506997.000000 480317.000000 1475611.000000 185726.322642*
*507196.000000 481012.000000 1475778.000000 185726.323642_
1 Comment
Stephen23
on 3 Jun 2017
Edited: Stephen23
on 3 Jun 2017
The file that you have uploaded and the file format that you have shown in your question are quite different: the lines are in a different order ("TAG_time" and "Reference" in the middle of the numeric data), and different lines exist (e.g. "datasets:"). This does not help us. We have no idea which of these is correct, or if both of these, or if there might be a wide range of input files formats that you want to be able to import, with other lines or different orders. It does not help because it makes your task specification unclear. It also does not help because while it is certainly possible to write code to read files with a range of formats, the wider the range of possible file formats the more complex the code. The stricter you can define the file format the simpler the code.
I would have been happy to write you something, but unless you specify exactly the format that needs to be imported then this would end up being one of those endless games of "I want A" -> okay, here is A ... "No, it needs to do B" -> here is B ... "Why is it not doing C?" -> you didn't ask for C, but here is C ... "I forgot to mention, my real files have D" -> sure, goodbye.
Please specify your file format accurately. Then you will get help.
Answers (1)
Walter Roberson
on 3 Jun 2017
S = fileread('data.txt');
as_lines = regexp(S, '\r?\n', 'split');
alphabetic_lines = regexp(as_lines, '^[A-Za-z].*$', 'match');
0 Comments
See Also
Categories
Find more on Language Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!