Visit Our UNIX and Linux User Community


converting epoch time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting converting epoch time
# 1  
Old 06-08-2011
converting epoch time

Hi,

Thanks bartus11 yesterday's code worked fine for me.
In meantime I've found another "issue".
As you can see highlighted, the time format in my original input in case of two rows which should be duplicited ,is differentwhat I need to do is to convert to this format "20110607-08:03:22" both 4 rows, as you can see in output
So in this case conversion from 30416938966 -> 20110607-08:26:56.
30416938966 - is microseconds elapsed since midnight.
20110607- current date
08:26:56 - converted from 30416938966
As you may remember the spaces between the columns should remain the same.
This should be the last modification , thanks a lot.

INPUT
Code:
H:                            EURB891                                     00440000000064.00000000000000045100000972 DE0006231004                             1IFXd                20110607-08:03:22BNABFRPP            DE  BNABFRPP            PARBFRPP                                                   #
H:                            EURS891                                     00440000000064.00000000000000045100000973 DE0006231004                             2IFXd                20110607-08:03:22BNABFRPP            DE  BNABFRPP            PARBFRPP                                                   #
H:                            EUR1B892                B892                10440000000450.00000000000000300100000984 FR0000130007                             1ALUp                30416938966TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A
H:                            EUR1S892                S892                10440000000450.00000000000000300100000985 FR0000130007                             2ALUp                30416938966TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R

OUTPUT
Code:
H:                            EURB891                                     00440000000064.00000000000000045100000972 DE0006231004                             1IFXd                20110607-08:03:22BNABFRPP            DE  BNABFRPP            PARBFRPP                                                   #
H:                            EURS891                                     00440000000064.00000000000000045100000973 DE0006231004                             2IFXd                20110607-08:03:22BNABFRPP            DE  BNABFRPP            PARBFRPP                                                   #
H:                            EURB892                                     00440000000450.00000000000000300100000984 FR0000130007                             1ALUp                20110607-08:26:56TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A
H:                            EURS892                                     00440000000450.00000000000000300100000985 FR0000130007                             2ALUp                20110607-08:26:56TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R

H:                            EUR1B892                B892                10440000000450.00000000000000300100000984 FR0000130007                             1ALUp                20110607-08:26:56TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #A
H:                            EUR1S892                S892                10440000000450.00000000000000300100000985 FR0000130007                             2ALUp                20110607-08:26:56TRADETESTBIC5       PA TRADETESTBIC5       TESTCLRXX                                                 #R

Thanks

Last edited by hernand; 06-08-2011 at 08:55 AM..
# 2  
Old 06-08-2011
Hi,

Can you post the the code which gives the output as shown above.
This User Gave Thanks to getmmg For This Post:
# 3  
Old 06-08-2011
30416938966 is not an epoch time, at least not this millennium it's not.

to convert from epoch to your format try
Code:
 perl -e'
@time=localtime($epoch) ;
printf "%d%.2d%0.2d-%0.2d:%0.2d:%0.2d\n", 
          $time[5]+1900, $time[4]+1, $time[3], $time[2], $time[1],$time[0];'

This User Gave Thanks to Skrynesaver For This Post:
# 4  
Old 06-08-2011
SORRY guys, I was informed now that 30416938966 is not epoch time, it defines microseconds elapsed since midnight of the day, the file was created(this file has to be created on daily basis).
So what I really need is to replace "30416938966 "in the file with "Current date" in this format "20110607", plus the time which we can parse from the value 30416938966 in this format "08:06:30"

This is the code I have now, its giving me output without time conversion.

Code:
#!/usr/bin/perl
open I, "$ARGV[0]";
@x=<I>;
$i=0;
for (@x){
  s/ +$//;
  $t=$_;
  @s=split / +/;
  if ($#s==10){
    $i=1;
    s/([^ ]+ +EUR)1([SB]\d+ +)[^ ]+( +)1/$1$2     ${3}0/;
    $s.=$_;
    $q.=$t;
  } elsif ($i) {
    $i=0;
    $s.=$q;
    $s.=$t;
  } else {
    $s.=$t;
  }
}
$s.=$q if $i;
print $s;


Last edited by hernand; 06-08-2011 at 08:46 AM..
# 5  
Old 06-08-2011
Quote:
Originally Posted by hernand
SORRY guys, I was informed now that 30416938966 is not epoch time, it defines microseconds elapsed since midnight of the day, the file was created(this file has to be created on daily basis).
So what I really need is to replace "30416938966 "in the file with "Current date" in this format "20110607", plus the time which we can parse from the value 30416938966 in this format "08:06:30"
So you need to divide by 1000 and add that to the creation time of the file in epoch. Something like the following:
Code:
perl -e 'open INPUT ,"<", "referenceFile";
@stat=stat(INPUT);
$asEpoch=$stat[10] +  (30416938966 / 1000); 
print int($asEpoch),"\n";'


Previous Thread | Next Thread
Test Your Knowledge in Computers #892
Difficulty: Medium
sed scripts cannot have comments.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: time intervals based on epoch time

I have a list of epoch times delimited by "-" as follows: 1335078000 - 1335176700 1335340800 - 1335527400 1335771300 - 1335945600 1336201200 - 1336218000 The corresponding dates are: 20120422 1000 - 20120423 1325 20120425 1100 - 20120427 1450 20120430 1035 - 20120502 1100 ... (3 Replies)
Discussion started by: alex2005
3 Replies

2. Shell Programming and Scripting

Converting a random epoch time into a readable format

I am trying to create a script that will take epoch (input from command line) and convert it into a readable format in bash/shell ---------- Post updated at 08:03 PM ---------- Previous update was at 07:59 PM ---------- #!bin/bash read -p "Please enter a number to represent epoch time:"... (9 Replies)
Discussion started by: sprocket
9 Replies

3. UNIX for Dummies Questions & Answers

Converting Epoch time

I have a Raspberry Pi that logs some temperatures using Onewire. Data is collected with RRDTool. The command sudo rrdtool fetch ute_temp.rrd AVERAGE -s -1h > ./test.log and then cat test.log gives the result 1388608500: 2.3579639836e+00 . How do I write a script that converts the Epoch time... (4 Replies)
Discussion started by: nilekl
4 Replies

4. Shell Programming and Scripting

Converting real time to epoch time

# date +%s -d "Mon Feb 11 02:26:04" 1360567564 # perl -e 'print scalar localtime(1360567564), "\n";' Mon Feb 11 02:26:04 2013 the epoch conversion is working fine. but one of my application needs 13 digit epoch time as input 1359453135154 rather than 10 digit epoch time 1360567564... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

converting epoch time to ddmmyy format

I can not find a working script or way to do this on sun solaris , can someone please guide me? e.g 1327329935 epoch secs = 012312 (ddmmyy) thanks (5 Replies)
Discussion started by: aliyesami
5 Replies

6. Programming

Converting a user inputted date to epoch time

Hi all , I need to know how to convert a time stamp entered by the user to be converted to GMT/UTC(epoch time) using mktime() and gmtime() for exapample the input will be put in the form ptm.tm_sec = 0; ptm.tm_min = 59; ptm.tm_hour = 11; ptm.tm_mday = 20;... (2 Replies)
Discussion started by: ada
2 Replies

7. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

8. Shell Programming and Scripting

epoch time

Hi all, I got a file with epoch times like this. 1264010700 1264097400 1263529800 1263762900 1263924300 What I want. I want all epoch times which are > current epoch time written to a file. So everything that is < will be ignored and not written to the file. Thanks (3 Replies)
Discussion started by: stinkefisch
3 Replies

9. Shell Programming and Scripting

how to convert date time to epoch time in solaris

Hi, Is there any easy way to convert date time(stored in shell variable ) to epoch time in solaris box? As +%s is working on linux but not on solaris, also -d option is not working. Any suggestion please? (6 Replies)
Discussion started by: anshuman0507
6 Replies

10. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

Featured Tech Videos