Search code examples
bashdateepoch

Cat file find epochs and then convert the epochs to date


i have a file with:

....1342477599376
    1342479596867
    1342480248580
    1342480501995
    1342481198309
    1342492256524
    1342506099378....

these lines ... means Various character. I'd like to read this file with cat (it is essential that i need to with that) and get these lines with sed commands, than i'd like to convert the epoch to date...

cat myfile.log  | sed '...*//' | sed 's/...*//' | date -d @$1

Unfortunately this isn't work.


Solution

  • One way, using sed:

    cat file.txt | sed "s/^.*\([0-9]\{13\}\).*/date -d @\1/" | sh
    

    Results:

    Thu Jun  4 14:16:16 EST 44511
    Sat Jun 27 17:07:47 EST 44511
    Sun Jul  5 06:09:40 EST 44511
    Wed Jul  8 04:33:15 EST 44511
    Thu Jul 16 05:58:29 EST 44511
    Sat Nov 21 05:42:04 EST 44511
    Fri Apr 29 10:56:18 EST 44512
    

    HTH