I am writing a section of awk code that reads a log file of this format:
[03/02/2020 10:01:01] SOME DATA [03/02/2020 10:05:25] SOME MORE DATA [03/02/2020 11:54:38] AND YET SOME DATA etc.
I wish to determine the epoch timestamp by combining the data in fields $1 and $2 and including a space between them to satisfy the input format needed by the bash date command.
This is the section of code I have written:
cmd="date -d" substr($1,2,10) substr($2,1,8) " +%s" cmd | getline this_date print this_date At the moment, when i run the script, i get this error...
date: invalid date ‘03/02/202010:01:01’ date: invalid date ‘03/02/202010:05:25’ date: invalid date ‘03/02/202011:54:38’ etc.
So it seems to me I am nearly there but, as expected, the date command wants a space between the date and time portions.
I have tried many ways to try and code a 'space' between substr($1,2,10) substr($2,1,8) in the first line of code above but each time I get an error.
Can anyone advise the best approach?
-dI suspect you do also have GNU awk (runawk --versionif you're not sure). Which timezone are the dates in your log file? Which timezone will you be running the tool from?