MATLAB Answers

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

2 views (last 30 days)
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 Comments

Mohammad Sami
Mohammad Sami on 3 Jan 2020
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 on 3 Jan 2020
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.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 3 Jan 2020
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;

More Answers (0)

Sign in to answer this question.

Products