I have read the following question: Convert from Unix time at the command line and Convert Any Format In Unix. I have tried a few different ways to convert my time 2017-10-12 00:34:26
which is in the date "+%F %T"
format to the date -R
format or Thu, 12 Oct 2017 00:34:26 -0400
.
Since I need to convert a list of dates like the following, I'm using $etime
as a variable for just one line of the file (until I got it working).
file1
:
2017-10-12 00:22:26
2017-10-12 00:25:26
2017-10-12 00:28:26
2017-10-12 00:31:26
2017-10-12 00:34:26
1st attempt:
etime=$(echo "2017-10-12 00:34:26"); date -Rd @$etime
2nd attempt:
etime=$(echo "2017-10-12 00:34:26"); | gawk '{print strftime("%c", $0)}'
Although these two didn't work, I was hoping to get them to work and then just loop the command for each line in file1
so the result would be:
Thu, 12 Oct 2017 00:22:26 -0400
Thu, 12 Oct 2017 00:25:26 -0400
Thu, 12 Oct 2017 00:28:26 -0400
Thu, 12 Oct 2017 00:31:26 -0400
Thu, 12 Oct 2017 00:34:26 -0400
Does anyone know an efficient way to convert these date formats in a list? Your help and support for the question is much appreciated.