extract date and time preceded by strings with variable length from text file
显示 更早的评论
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!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!