Parsing one line data-set into array using textscan?

2 views (last 30 days)
Hi!
I am trying to parse the return from a traceroute system command. The output from it comes from a single row, single column char of around 600 characters:
Data example:
1 192.168.0.1 1.610 ms 1.211 ms 1.459 ms 2 146.172.110.121 25.653 ms 30.442 ms 29.061 ms 3 146.172.99.125 39.904 ms 51.665 ms 38.419 ms
Now, I have had no problems with parsing the first part of this into an array, but I would like to make a new row in the array for each new index, e.g. 1, 2, 3 as can be seen in the data above.
The end result would be something like (but in an array/matrix):
1 192.168.0.1 1.610 ms 1.211 ms 1.459 ms
2 146.172.110.121 25.653 ms 30.442 ms 29.061 ms
3 146.172.99.125 39.904 ms 51.665 ms 38.419 ms
Current Code:
[status, result] = system('traceroute -n 209.85.173.147 2> /dev/null | head -30 ');
TraceArray = textscan(result,'%f %s %f %*s %f %*s %f', 'delimiter', ' ', 'MultipleDelimsAsOne', 1);
with Best Regards,
Adam

Accepted Answer

TAB
TAB on 5 Jan 2012
TraceArray = textscan(result,...
'%f %s %f %*s %f %*s %f %s', 'delimiter', ' ', 'MultipleDelimsAsOne', 1)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!