MATLAB Answers

How do I import a complicated .txt file?

1 view (last 30 days)
Hans Franz
Hans Franz on 7 Jan 2018
Answered: Kris Fedorenko on 9 Jan 2018
Hi everyone, I have I quite difficult .txt to Import into Matlab. There are header lines after every segment. The first rows of the file look like this:
2017-10-17T09:02:03,099091678+00:00
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:06 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:07 --:--:-- 0
100 1024 100 1024 0 0 135 0 0:00:07 0:00:07 --:--:-- 135
2017-10-17T09:02:10,957307712+00:00
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 15 100 15 0 0 84 0 --:--:-- --:--:-- --:--:-- 84
2017-10-17T09:02:11,205189925+00:00
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 10240 100 10240 0 0 55063 0 --:--:-- --:--:-- --:--:-- 55351
2017-10-17T09:02:11,458842315+00:00
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 15 100 15 0 0 135 0 --:--:-- --:--:-- --:--:-- 136
end
I want to import this into a structure which should look like this:
Import.date
Import.time
Import.Total
Import.Received
Import.Xferd
...
Actually I have no idea how to import this... Because of the complexity, importdata does not work...
I am thankful for every answer, thanks!

  0 Comments

Sign in to comment.

Answers (1)

Kris Fedorenko
Kris Fedorenko on 9 Jan 2018
I would suggest copy-pasting each segment into a separate Excel file and using the "Text to Columns" functionality:
Then it should be easy to import each segment with "readtable" or Import Tool.
If the number of segments is prohibitive for this kind of manual processing, you can also copy-paste the entire file to Excel, and then use Import Tool to disregard the text.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products