Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Get the epoch time and add it as a new column

I have the following tab separated input file, with timestamps in UTC. How can I calculate the epoch time an add it as a new column? It is a large file with over 60MM rows.
a   b
0 2020-03-03 15:46:52
1 2020-03-02 11:05:17


Output:
a   b                   c  
0 2020-03-03 15:46:52 1583279212
1 2020-03-02 11:05:17 1583175917
by

1 Answer

Bharatv4tg1
I'm not sure how suitable it will be for large files, but you try do something like this with Miller
$ TZ=UTC mlr --pprint --fs tab put -S '$c = strftime(strptime($b,"%Y-%m-%d %H:%M:%S"),"%s")' file
a b c
0 2020-03-03 15:46:52 1583250412
1 2020-03-02 11:05:17 1583147117

(although I just noticed it appears to screw up the header alignment when the OFS is tab ...).

Login / Signup to Answer the Question.