1
I have a log file with timestamps in format of "22.09.2016 08:22:54" ("+%Y:%m:%d %H:%M:%S"). This timestamp is in UTC timezone.
Now I have to convert this timestamp to Europe/Helsinki timestamp using bash script.
I have this script which makes the conversion as I want.
#!/bin/bash
sec=$(TZ="UTC" date +'%s' -d "2015-05-20 18:05:02")
TZ="Europe/Helsinki" date -d "@$sec" "+%Y:%m:%d %H:%M:%S"
This works fine but the date "input" format ( -d "2015-05-20 18:05:02" ) is different format comparing to my log timestamp format.
I would like to change this script to something like this..
#!/bin/bash
sec=$(TZ="UTC" date +'%s' -d "$1")
TZ="Europe/Helsinki" date -d "@$sec" "+%Y:%m:%d %H:%M:%S"
Where the $1 can be in the original date format of my log file "22.09.2016 08:22:54" ("+%Y:%m:%d %H:%M:%S").
I cannot make this to work.. Can someone help me with this one.. Thank you
EDIT:
I have tried something like this and many other combinations..
#!/bin/sh
sec=$(TZ="UTC" date +'%s' "+%Y:%m:%d %H:%M:%S" -d "$1")
TZ="Europe/Helsinki" date -d "@$sec" "+%Y:%m:%d %H:%M:%S"
but his ends up with error..
date: extra operand ‘+%Y:%m:%d %H:%M:%S’
Try 'date --help' for more information.
date: invalid date ‘@’
Did you try to set a format for your first line? – Seth – 2016-09-23T05:54:46.020
yes.. I have tried this..
#!/bin/sh sec=$(TZ="UTC" date +'%s' "+%Y:%m:%d %H:%M:%S" -d "$1") TZ="Europe/Helsinki" date -d "@$sec" "+%Y:%m:%d %H:%M:%S"
but his ends up with error..
date: extra operand ‘+%Y:%m:%d %H:%M:%S’ Try 'date --help' for more information. date: invalid date ‘@’ – user3647376 – 2016-09-23T05:58:32.980