Consider some data that looks like this:
"2019-12-12 00:00:01","2012-01-01 01:01:01"
I wish to replace it so that they are valid datetime json values:
"2019-12-12T00:00:01+01","2012-01-01T01:01:01+01"
I tried writing the following sed command:
sed 's/"([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) ([0-9][0-9]:[0-9][0-9]:[0-9][0-9])"/\1T/g' test.csv > testnew.csv
However, this gives the follow error:
sed: -e expression #1, char 99: invalid reference \1 on `s' command's RHS
Why is this happening, and how do I refer to the submatches of a regex search?
(
and)
are literal in BRE - so nothing is being captured. Use\(
and\)
or switch to extended mode (-E
or-r
). – steeldriver Aug 20 '19 at 00:13json
please consider adding a full working in- and output, so that we can propose a good solution. I have the feeling thatsed
is not really the way to go here ... e.g. a Python solution might be way easier and better. – pLumo Aug 20 '19 at 07:23