I tried use sed with /e
option to call date -d @
to convert epoch to human readable date time but it seems that sed works only if the input line is very simple
I prepared a bash file to simply convert epoch in my format and copied it in usr/local/bin
that it's in my $PATH
#!/bin/bash
date +'%Y-%m-%d %T %Z' -d @$1
and I can demonstrate that it works fine:
$ echo 1616720904 | sed 's/\(.*\)/epoch-to-date \1/e'
2021-03-26 02:08:24 CET
but:
- if you input a complex string like usually, you have from a log file, it doesn't work:
$ echo "timestamp:1616720904" | sed 's/\(timestamp\:\)\([0-9]*\)/`epoch-to-date \2`/e'
sh: 1: 2021-03-26: not found
as you can see 2021-03-26
is part of the converted date time and seems passed to the bash again sh: .... not found
- if you have more text in the input string it pass all text to the bash:
$ echo "version:123,timestamp:1616720904" | sed 's/\(timestamp\:\)\([0-9]*\)/`epoch-to-date \2`/e'
sh: 1: version:123,2021-03-26: not found
The output I would get is:
version:123,timestamp:2021-03-26 02:08:24 CET