Meskipun bukan bash murni, skrip berikut akan mengonversi stempel waktu dengan panjang 13 dalam string ke tanggal yang setara di zona waktu lokal Anda menggunakan perl
timestamp_to_date.sh
#!/usr/bin/env bash
IT=$(cat /dev/stdin)
re='(.*)([0-9]{13})(.*)'
while [[ $IT =~ $re ]]; do
TIMESTAMP=${BASH_REMATCH[2]}
AS_DATE=$(echo "$TIMESTAMP" | perl -pe 's/([\d]{10})([\d]{3})/localtime $1/eg;')
IT="${IT/$TIMESTAMP/$AS_DATE}"
done
echo "$IT"
memasukkan
{"timestamp":"1573121629939","level":"DEBUG","thread":"http-nio-15372-exec-3","logger":"org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor"}
keluaran
$ cat input | timestamp_to_date.sh
{"timestamp":"Thu Nov 7 06:13:49 2019","level":"DEBUG","thread":"http-nio-15372-exec-3","logger":"org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor"}
date -d @$(date -u +%s)