0

I want to convert dates in a file to epoch time. A sample csv looks like this:

$ cat test.jtl 
2016/09/19 00:31:17.080,238,test1  
2016/09/19 00:31:17.154,322,test2 
22-Sep-2014 10:32:35.012,222,test3

I have tried the following , but the result just gets the current date

cat test.jtl  | gawk 'BEGIN{FS=OFS=","} {command="date -d \"$1\" +'%s%3N'";command | getline $1;close(command);print}'

But this returns only the current date in epoch. I think the $1 ( the first data column , which is a date ) is not being passed in properly. But not sure what the issue is.

1

Quoting of the assignment to command is stopping expansion of $1.

cat test.jtl | gawk 'BEGIN{FS=OFS=","} {command="date -d \""$1"\" +'%s%3N'";command |getline;close(command);print}'

works for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.