Reputation: 1575
I have a file with this format
Time Temp
11:13:23 22.6
11:13:25 22.5
11:13:27 22.6
11:13:29 22.6
11:13:31 22.6
11:13:33 22.6
11:13:35 22.7
I need to replace the time with date time and add a current column.
Date/Time Temp Current
2018-04-13 11:13:23 22.6 0.020
2018-04-13 11:13:25 22.5 0.020
2018-04-13 11:13:27 22.6 0.020
2018-04-13 11:13:29 22.6 0.020
2018-04-13 11:13:31 22.6 0.020
2018-04-13 11:13:33 22.6 0.020
i can find the text i want replaced but I'm struggling to replace it.
Find what \d\d:\d\d:\d\d\t\d\d.\d
Replace with 2018-04-13 "$1" 0.020
I end up with
2018-04-13 "" 0.020
Please let me know what i am doing wrong thanks.
Upvotes: 1
Views: 46
Reputation: 626690
The problem is that you reference a value of the first capturing group with $1
, but your pattern has no capturing group.
You may use your pattern or this one (almost identical to yours, note the escaped .
to only match a literal dot):
\d{2}:\d{2}:\d{2}\t\d{2}\.\d
Or - if you need to only match whole lines - add line anchors:
^\d{2}:\d{2}:\d{2}\t\d{2}\.\d$
and replace with
2018-04-13\t$0\t0.020
The $0
in the replacement pattern stands for the whole match value, no need to wrap the whole pattern with a capturing group.
Upvotes: 1