Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Shell script to convert epoch time to real time

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-25-2011   -   Original Discussion by aismann
aismann's Unix or Linux Image
aismann aismann is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 15 February 2012, 12:05 PM EST
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Shell script to convert epoch time to real time

Dear experts,

I have an epoch time input file such as : -


Code:
1302451209564
1302483698948
1302485231072
1302490805383
1302519244700
1302492787481
1302505299145
1302506557022
1302532112140
1302501033105
1302511536485
1302512669550

I need the epoch time above to be converted into real time into an output file such as below. Im in malaysia which is GMT +8 : -

1302451209564 -10 Apr 2011 16:00:20

Last edited by Yogesh Sawant; 04-25-2011 at 05:40 AM.. Reason: added code tags
Sponsored Links
    #2  
Old Unix and Linux 04-25-2011   -   Original Discussion by aismann
frans's Unix or Linux Image
frans frans is offline Forum Advisor  
Registered User
 
Join Date: Oct 2009
Last Activity: 1 February 2016, 9:47 AM EST
Location: France
Posts: 839
Thanks: 4
Thanked 54 Times in 53 Posts
Those are not valid timestamps, but here's the "script": (works with GNU date)


Code:
while read S; do date -d @$S; done <infile

Sponsored Links
    #3  
Old Unix and Linux 04-25-2011   -   Original Discussion by aismann
aismann's Unix or Linux Image
aismann aismann is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 15 February 2012, 12:05 PM EST
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Frans. But im using Solaris 8. It does not seem to support date -d.
Is there another option? Thanks
    #4  
Old Unix and Linux 04-25-2011   -   Original Discussion by aismann
Yogesh Sawant's Unix or Linux Image
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
 
Join Date: Sep 2006
Last Activity: 26 February 2018, 8:57 AM EST
Location: Rossem, Tazenda
Posts: 1,213
Thanks: 7
Thanked 18 Times in 17 Posts
if you could use Perl:

Code:
# perl -e 'print scalar localtime(1302451209564), "\n";'
Wed Jan 14 00:09:24 43243
#

Sponsored Links
    #5  
Old Unix and Linux 04-25-2011   -   Original Discussion by aismann
aismann's Unix or Linux Image
aismann aismann is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 15 February 2012, 12:05 PM EST
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Yogesh
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to convert date time to epoch time in solaris anshuman0507 Shell Programming and Scripting 6 08-22-2009 10:28 PM
Convert Epoch Time to Standard Date and Time & Vice Versa DrivesMeCrazy Shell Programming and Scripting 5 02-07-2009 12:40 AM
Convert Epoch time format to normal date time format in the same file rk4k Shell Programming and Scripting 3 11-19-2008 09:04 PM
EPOCH to real time? TheEngineer UNIX for Advanced & Expert Users 5 07-18-2006 08:30 AM
Convert from standard epoch time from a shell script? LordJezo Shell Programming and Scripting 4 09-18-2005 11:48 PM



All times are GMT -4. The time now is 09:17 PM.