Convert epoch time stamp into human readable format

Can someone help me to write a shell script to convert epoch timestamp into human readable format

1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
1394553600,"test2","34.233830","34.132758","10086.9180","9933.306071"
1394553600,"test3","10617.3400","8794.801030","1072.77640","783.440867"
1394553600,"test4","9900.946","9852.964286","11260.573","11231.444714"

the first field denotes epoch time stamp

What would be the desired output for this sample data?

Assuming your first column is the epoch time
you can do this (from man date)

date --date='@2147483647'

nput

"_time",mynode,"Data1","Data2","Data3","Data4"
1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
1394553600,"test2","34.233830","34.132758","10086.9180","9933.306071"
1394553600,"test3","10617.3400","8794.801030","1072.77640","783.440867"
1394553600,"test4","9900.946","9852.964286","11260.573","11231.444714"

Expected Output

"_time",mynode,"Data1","Data2","Data3","Data4"
3/11/2014 16:00:00"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
3/11/2014 16:00:00,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
3/11/2014 16:00:00,"test2","34.233830","34.132758","10086.9180","9933.306071"
3/11/2014 16:00:00,"test3","10617.3400","8794.801030","1072.77640","783.440867"
3/11/2014 16:00:00,"test4","9900.946","9852.964286","11260.573","11231.444714"

if possible can i get the time stamp in EST time zone

---------- Post updated at 01:36 PM ---------- Previous update was at 01:36 PM ----------

Input

"_time",mynode,"Data1","Data2","Data3","Data4"
1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
1394553600,"test2","34.233830","34.132758","10086.9180","9933.306071"
1394553600,"test3","10617.3400","8794.801030","1072.77640","783.440867"
1394553600,"test4","9900.946","9852.964286","11260.573","11231.444714"

Expected Output

"_time",mynode,"Data1","Data2","Data3","Data4"
3/11/2014 16:00:00"test","79799776.0","19073982.728571","77547576.0","18835699.285714"
3/11/2014 16:00:00,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"
3/11/2014 16:00:00,"test2","34.233830","34.132758","10086.9180","9933.306071"
3/11/2014 16:00:00,"test3","10617.3400","8794.801030","1072.77640","783.440867"
3/11/2014 16:00:00,"test4","9900.946","9852.964286","11260.573","11231.444714"

if possible can i get the time stamp in EST time zone

try this

while read line;do
  ts=`echo "$line"|cut -f1
  rest=`echo "$line"|cut -f2-
  d=`date --date="@${ts}"
  echo "$d,$rest"
done < inputfile > output file

it's not working... :frowning:

do you see errors, or the output file is not what you want?

it's converting all time stamp to Wed Mar 12 00:00:00 EDT 2014@, whatever the epoch time stamp is and i am getting output as
Wed Mar 12 00:00:00 EDT 2014@,
Wed Mar 12 00:00:00 EDT 2014@,
Wed Mar 12 00:00:00 EDT 2014@,

the remianing fields are not coming

oh my bad,

while read line;do
  ts=`echo "$line"|cut -d',' -f1
  rest=`echo "$line"|cut -d',' -f2-
  d=`date --date="@${ts}"  "+%d/%m%Y %H:%M:%S"`
  echo "$d,$rest"
done < inputfile > output file
1 Like

Review the 2nd and 3rd lines. Aren't you missing some back-quotes?

Using GNU awk

awk -F, '{$1=strftime("%m/%d/%Y %H:%M:%S", $1)}1' OFS=, infile