I have json lines that contain multiple parts per line that look like this:
"SomeDate":"Date(-2156284800000)",
I would like to convert each occurrence in all lines into something more human readable:
"SomeDate":"1901-09-03 00:19:32",
I tried using sed to put the matched block (in this case the timestamp) into the argumentlist of the date command. This fails.
$ echo '"SomeDate":"Date(-2156284800000)",' | \
sed "s/Date(\([0-9\-]*\)[0-9][0-9][0-9])/$(date -d@\\1 \"+%F %T\")/g"
date: invalid date `@\\1'
"SomeDate":"",
In an attempt to debug this all I added an 'echo' to the date to validate the command it should be running
$ echo '"SomeDate":"Date(-2156284800000)",' | \
sed "s/Date(\([0-9\-]*\)[0-9][0-9][0-9])/$(echo date -d@\\1 \"+%F %T\")/g"
"SomeDate":"date -d@-2156284800 "+%F %T"",
$ date -d@-2156284800 "+%F %T"
1901-09-03-00:19:32
Why isn't the first command running as expected?
The best guess I have right now is that the subshell is executed first WITHOUT the \1 substitution and then the resulting output is actually used by sed.
How do I achieve what I'm trying to do?
P.S. I'm using CentOS 6.6