It is a strange method to read a file line by line by frewind-ing it in each iteration. It would be much cheapter to import the file at once and perfomr the sorting afterwards. Note that the disk access is 1000 times slower than accessing the data in the RAM.
The
formatSpec = '%f%f%f%f%f%f%f%*s%*s%*s%[^\n\r]';
and the data:
20170730,Xavi,3237.531009,2083.298925,501.542962,404.082872,162.895678,85.710573,121,1,89,7,8,26.156520,4.672901
do not match: As the error message tells clearly already, the 2nd input is not a number. What about:
formatSpec = '%f%s%f%f%f%f%f%*s%*s%*s%[^\n\r]';