Sponsored Content
Full Discussion: epoch conversion
Top Forums Shell Programming and Scripting epoch conversion Post 302349523 by satchy321 on Tuesday 1st of September 2009 07:12:01 AM
Old 09-01-2009
epoch conversion

I need to convert an epoch time from a file into a standard UTC time and output it in the same format but I'm not sure what's the best approach

here's the input file and the bold part is what I need to convert.

1,1,"sys1",60,300000
2,"E:",286511144960
3,1251194521,"E:",0,0
3,1251194581,"E:",8,0
3,1251194641,"E:",17,0
3,1251194701,"E:",8,0
3,1251194761,"E:",25,0
3,1251194821,"E:",34,0
3,1251194881,"E:",145,0
3,1251194941,"E:",1646,0
3,1251195001,"E:",8,0

I want the output file to look like this

1,1,"sys1",60,300000
2,"E:",286511144960
3,Tue Aug 25 11:02:01 2009,"E:",0,0
3,Tue Aug 25 11:03:01 2009,"E:",8,0
3,Tue Aug 25 11:04:01 2009,"E:",17,0
3,Tue Aug 25 11:05:01 2009,"E:",8,0
3,Tue Aug 25 11:06:01 2009,"E:",25,0
3,Tue Aug 25 11:07:01 2009,"E:",34,0
3,Tue Aug 25 11:08:01 2009,"E:",145,0
3,Tue Aug 25 11:09:01 2009,"E:",1646,0
3,Tue Aug 25 11:10:01 2009,"E:",8,0

So I googled around and wrote some lines but I don't think it's the way to do it.

##############################################################
#!/bin/ksh


#skip 1st 2 lines and grab the epoch time
tail +3 file1| awk -F',' '{print $2}' > /temp/time

## replace the epoch time with UTC
for time in `cat /temp/time| awk '{print $1}'`
do
perl -e 'print scalar localtime ('$time'), "\n"'

done

rm /temp/time
##############################################################


I now have the time converted but how do I output it in the same format ?
I don't script too often as you can see and would appreciate assistance.

Cheers.
G
 

10 More Discussions You Might Find Interesting

1. Programming

Epoch problem

I would like to know if the "Epoch" problem (on September 9, 2001) i.e. when the Unix clock counter will hit 100000000 will create a problem for programs that are dependent on system and server times. I am presently part of a team that is working on Oracle database on SUN SOLARIS based servers.... (2 Replies)
Discussion started by: vsomanchi
2 Replies

2. UNIX for Dummies Questions & Answers

Epoch

Hi all, i am trying to figure out how i can get a 'Nix box to display epoch time. Is there a command to do this? Do I know what I am talking about or am I an Idiot? Wait dont answer that last question!!!!! Thanx in advance!!!:confused: (2 Replies)
Discussion started by: Bodhi
2 Replies

3. Shell Programming and Scripting

conversion from EPOCH timestamp to local time zone

hello gurus, i want a perl/shell script which once invoked should convert a set of EPOCH timestamps to local time ( IST..i want) . how does it work ,i have an idea on that..but writing a perl/shell script for it is not possible for me...so i need help for the same. my exact requirement is... (2 Replies)
Discussion started by: abhijeetkul
2 Replies

4. Shell Programming and Scripting

Epoch time

Guys, i have a question... I have 2 sets of data say "a" and "a+1" which has values in epoch time.. Question is... if i were to get the time difference where diff = "a+1" - "a" can i convert it back to real time duration after the subtraction... OR i need to convert em first before i do the... (1 Reply)
Discussion started by: 12yearold
1 Replies

5. Shell Programming and Scripting

Date conversion from Standard/given format to seconds/epoch

I am trying get time difference of two dates in secs. Initially I want to convert a standard date format to epoch for two dates and then subtract the two epoch dates. Example : date -d "2007-09-01 17:30:40" '+%s' But this gives me below error date: illegal option -- d Usage: date OS: AIX... (6 Replies)
Discussion started by: bpaac
6 Replies

6. Shell Programming and Scripting

Epoch & Unix Timestamp Conversion Tools

Hi All, Please read the below data carefully. I need an unix command for converting unix timestamp to Epoch timestamp. I need to daily convert this today's unix(UTC) time to epoch time, so i am thinking to make a shellscript for this. Please help me for this by providing... (3 Replies)
Discussion started by: aish11
3 Replies

7. Shell Programming and Scripting

Shell Script for Epoch Time Conversion

Hi there I came across this script online to convert Epoch time to proper date format, but I am receiving the following error Also, I have HISTTIMEFORMAT set in user's .profile so that their history output shows time stamps. Additionally I have changed their .history location to a dedicated... (9 Replies)
Discussion started by: hedkandi
9 Replies

8. Shell Programming and Scripting

Epoch in Perl

Hi, Can anybody tell me how time is calculated in the below or what is actually being done here? Also can you explain in simple words about epoch time and why it is used? Thanks in advance (1 Reply)
Discussion started by: irudayaraj
1 Replies

9. Shell Programming and Scripting

Different epoch conversion result for bash and csh users

Hi there I'm using this script to convert command line history with Epoch time stamp to human readable. While it works fine with users with /bin/csh shell, it fails to convert for users with /bin/bash shell. Why is this happening? I even changed and added * and after the # but it still didnt... (2 Replies)
Discussion started by: hedkandi
2 Replies

10. Programming

Python conversion to epoch time

Hi. I have timestamps that I am trying to convert to epoch time. An example: I am trying to convert this to an epoch timestamp but have one little glitch. I have this: import time date_time = '' pattern = '' epoch = int(time.mktime(time.strptime(date_time, pattern))) print epoch... (1 Reply)
Discussion started by: treesloth
1 Replies
function::ctime

FUNCTION:(3stap)					      Time utility functions						  FUNCTION:(3stap)

NAME
function::ctime - Convert seconds since epoch into human readable date/time string SYNOPSIS
ctime:string(epochsecs:long) ARGUMENTS
epochsecs Number of seconds since epoch (as returned by gettimeofday_s) DESCRIPTION
Takes an argument of seconds since the epoch as returned by gettimeofday_s. Returns a string of the form "Wed Jun 30 21:49:08 1993" The string will always be exactly 24 characters. If the time would be unreasonable far in the past (before what can be represented with a 32 bit offset in seconds from the epoch) the returned string will be "a long, long time ago...". If the time would be unreasonable far in the future the returned string will be "far far in the future..." (both these strings are also 24 characters wide). Note that the epoch (zero) corresponds to "Thu Jan 1 00:00:00 1970" The earliest full date given by ctime, corresponding to epochsecs -2147483648 is "Fri Dec 13 20:45:52 1901". The latest full date given by ctime, corresponding to epochsecs 2147483647 is "Tue Jan 19 03:14:07 2038". The abbreviations for the days of the week are 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', and 'Sat'. The abbreviations for the months are 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', and 'Dec'. Note that the real C library ctime function puts a newline (' ') character at the end of the string that this function does not. Also note that since the kernel has no concept of timezones, the returned time is always in GMT. SystemTap Tapset Reference May 2013 FUNCTION:(3stap)
All times are GMT -4. The time now is 04:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy