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

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

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

Hi,

Can you post the the code which gives the output as shown above.

1 Like

30416938966 is not an epoch time, at least not this millennium it's not.

to convert from epoch to your format try

 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];'
1 Like

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.

#!/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;

So you need to divide by 1000 and add that to the creation time of the file in epoch. Something like the following:

perl -e 'open INPUT ,"<", "referenceFile";
@stat=stat(INPUT);
$asEpoch=$stat[10] +  (30416938966 / 1000); 
print int($asEpoch),"\n";'