I have a date like "2014-01-30 05:04:27 GMT", and if I run date -d "2014-01-30 05:04:27 GMT", the output is in my server's timezone ("Thu Jan 30 16:04:27 EST 2014").
With the use of grep and cut, I have extracted the date in GMT from a file. However, I am struggling to then convert this into my local time.
For example:
[user@server log]# grep "something" logfile.txt | grep "Succeeded" | cut -f1 -d'['
Output: 2014-01-30 05:04:27 GMT
What can I add on the end, to pass that output to "date -d"?
Attempted:
gmt="$(grep "something" logfile.txt | grep "Succeeded" | cut -f1 -d'[')"
date -d "$gmt"
Or, if you prefer the pipeline format:
grep "something" logfile.txt | grep "Succeeded" | cut -f1 -d'[' | { read gmt ; date -d "$gmt" ; }
The problem is that date
does not use stdin. Thus, we have to capture the stdin into a variable (called gmt
here) and then supply that on the command line to date
.
Sample output from the second approach:
$ echo "2014-01-30 05:04:27 GMT" | { read gmt ; date -d "$gmt" ; }
Wed Jan 29 21:04:27 PST 2014
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments