I have a human written text file that contains time stamps in form of dd-mm-yyyy
,HH:MM
or HH:MM:SS
. I have managed to extract time stamps from text file using regex but I would like to also get a line of corresponding time stamp. It would be nice to have time stamps in one file and corresponding lines in the other. There could be multiple time stamps per line so same line should occur multiple times.
If this can be done, what if I want only few words or few lines around a time stamp. Idea is just to get time stamps and their context extracted.
For now I have been using Matlab for this, but any Unix tool that's supported on MacOS and portable git bash for Windows. The Mac's grep
doesn't support the -P
option for Perl regex, which is needed for look around (?<![0-9])
.
Here is example of original file and desired outputs:
original:
L&L logfile
14-5-12
16-05-2012
Experiment 1
Device 77212-123-123123
Instrument 2, 34g, 66hz
Notes:
Something weird happened 12:34
Everything is fine 13:07
Log
8:00 routine 1
8:20 routine 2
8:40 routine 3, 8:45 something went south
8:50 routine 4, 8:50:12 weird peak at data
output1:
14-5-12
16-05-2012
12:34
13:07
8:00
8:20
8:40
8:45
8:50
8:50:12
output2:
14-5-12
16-05-2012
Something weird happened 12:34
Everything is fine 13:07
8:00 routine 1
8:20 routine 2
8:40 routine 3, 8:45 something went south
8:40 routine 3, 8:45 something went south
8:50 routine 4, 8:50:12 weird peak at data
8:50 routine 4, 8:50:12 weird peak at data
grep
, add e.g.-2
to get two adjacent lines too. Though repeats won't be done nicely with just grep.(\w*\s){2}
(preceding) or(\s\w*){2}
(following). Lines would be something like(^.*\n.*){2}
for 2 preceding lines and(.*\n.*){2}
for 2 following lines, assuming the text has distinct new-line breaks and not just wrapped text.