I propose another solution. This code is the shortest in MATLAB code. Using sed first, we format the file as a CSV file (shared comma, each record on the same line):
cat a.dat | sed -e 's/,//g ; s/[ \t]*$/,/g' -e '0~8 s/^\(.*\),$/\1\n/' | sed -e :a -e '/,$/N; s/,\n/,/; ta' -e '/^$/d' > file.csv
The explanation . First, we get rid of thousands of comma delimiters and trim the spaces at the end of each line, adding a comma. But then we remove this trailing comma for every eighth line. Finally, we join the rows and delete the empty ones.
The result will look like this:
1999-01-04,1100.00,1060.00,1092.50,0,6225,1336605,37 1999-01-05,1122.50,1087.50,1122.50,0,3250,712175,14
Further in MATLAB, we simply use textscan to read each line: the first field as a string (to convert to num), and the rest as numbers:
fid = fopen('file.csv', 'rt'); a = textscan(fid, '%s %f %f %f %f %f %f %f', 'Delimiter',',', 'CollectOutput',1); fclose(fid); M = [datenum(a{1}) a{2}]
and the resulting matrix M is equal to:
730124 1100 1060 1092.5 0 6225 1336605 37 730125 1122.5 1087.5 1122.5 0 3250 712175 14