in reply to Re^2: Epoch time conversion script
in thread Epoch time conversion script

Could you please post some sample lines from 32adm_bash_history so we can see the format of your file? And what your expected output would look like?

Replies are listed 'Best First'.
Re^4: Epoch time conversion script
by hedkandi (Initiate) on Mar 28, 2012 at 08:59 UTC

    Hi anonymous This is the sample history file with hashed Epoch time in seconds taken from a different user:

    [root@H99A105 user_history]# tail -f sapr3_history #+1331257705 Date is: Fri Mar 9 10:48:25 JST 2012 #+1331257706 history

    After the conversion it should look like this:

    [root@H99A105 user_history]# tail -f /var/log/user_history/Epoch_Conve +rt/sapr3 Fri Mar 9 10:48:25 JST 2012 Date is: Fri Mar 9 10:48:25 JST 2012 Fri Mar 9 10:48:26 JST 2012 history
      Something like this should do what you want.

      open my $in, '<', 'infile.txt' or die "Bummer: $!"; open my $out, '>', 'outfile.txt' or die "What: $!"; while(my $line = <$in>){ if(my ($epoch) = $line =~ /^#\+(\d+)\s*$/){ my $human_readable = `date -d \@$epoch`; # or: # my $human_readable = scalar localtime $epoch; print $out $human_readable; } else{ print $out $line; } }

        Hi lidden I used the while loop you provided and I'm getting this error

        [root@H99A115 03]# ./convert ./convert: line 4: syntax error near unexpected token `{' ./convert: line 4: `while(my $line = $in){'

        I removed the <> tags from <$in> and still the same error this is my input and output file:

        open my $in, '<', 'q22adm_history' or die "Bummer: $!"; open my $out, '>', 'q22adm' or die "What: $!";
      One liner (Using Windows style quotes. Change to Single quote for linux):
      perl -pe "m/^#\+(\d+)/ and $_=scalar localtime $1" InputFileName > Ou +tputFileName

                   All great truths begin as blasphemies.
                         ― George Bernard Shaw, writer, Nobel laureate (1856-1950)

        Hi netwallah You're a genius! This totally solved my issue. Im going to add this to cron rightaway! Thanks!

        Ok I should probably add also that it works for C shell users only! But thank you nevertheless!