Append date to time column entries where time is sporadically placed throughout the table

2 次查看(过去 30 天)
My data looks something like this:
time: service: user: otherdata:
09:00:00 @SERVICE first.last@machineName somedata
09:00:03 @SERVICE TIMESTAMP 12/31/2019
09:05:00 @SERVICE first.last@machineName somedata
09:08:00 @SERVICE first.last@machineName somedata
What I would like to do is append that 12/31/2019 to the time column, but the problem is that it's sporadically placed throughout the file. The main consistancy is the TIMESTAMP data that's in the user column, but I'm not exactly sure how to format the parsing to find it.
Any help would be greatly apprecaited.
  2 个评论
Mohammad Sami
Mohammad Sami 2020-1-3
If the format of the row with date is alway the same, you can use that to find the rows which contain date.
index = contains(stringdata,'@SERVICE TIMESTAMP');
rows_with_timestamp = stringdata(index);
% you can then parse using regexp textscan e.t.c
Tyler Rohren
Tyler Rohren 2020-1-3
I'm more concerned with appending that data to the time entry and then changing to the next one when the timestamp updates to a newer date, and idea on how to do that? The parsing it's that big of a deal.

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2020-1-3
Identifying a "best" solution will require some creativity and some knowledge of your data. Here's one simple approach that may get you started.
data = readtable('TylerRohren_data.txt')
ind = find(string(data.user_)=="TIMESTAMP",1,"first");
TS = datetime(data.otherdata_(ind));
for r = 1:height(data)
if string(data.user_(r))=="TIMESTAMP"
TS = datetime(data.otherdata_(r),'InputFormat',"MM/dd/uuuu");
end
time(r,1) = TS + data.time_(r);
end
data.time_ = time;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by