extract date and time preceded by strings with variable length from text file
Mostrar comentarios más antiguos
Hi all,
I am facing the challenge of extracting date and time from the following table.
>>460110419137703 0 2018-09-28 01:23:10 0.000000 0.000000
>>460028186815737 0368ceefe32555 2018-09-28 01:19:25 113.944056 22.504925
I have tried the following command but it only manages to extract the second line correctly.
>>tmp = readtable('1.txt','ReadVariableNames',false,'Format','%f%s%{yyyy-MM-dd HH:mm:ss}D%f%f');
One way to go around this is to replace '0' in the first line with a string of fourteen 0's to match the string length and then use the following command.
>>tmp = readtable('1.txt','ReadVariableNames',false,'Format','%f%14c%{yyyy-MM-dd HH:mm:ss}D%f%f');
But I think there may be a single command that can handle both lines without manual modification as above. Could somebody give me an idea how this could be done? Thanks!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!