I am looking for awk command to change the time column of a text file to its nearest 5 minute interval. So 12:56:59 become 12:55:00
The following command works as expected. Thanks for the response.
head r_SERVER_2012-03-10-12-55-00 | awk -F'^' '{print $7}' | awk '{split($2, a, ":"); printf "%s %s:%02d:00\n", $1, a[1],int(a[2]/5)*5}'
Correct result:
2012-03-10 12:55:00
But I want to show fields other than date as well. The following does not work:
head r_SERVER_2012-03-10-12-55-00 | awk -F'^' '{print $1, $2, $7, $8}' | awk '{split($2, a, ":"); printf "%s %s:%02d:00\n", $1, a[1],int(a[2]/5)*5}'
Wrong result:
565 14718:00:00
It should be …
565 123 2012-03-10 12:55:00 country
You don’t need multiple awk commands, just one, and you can set awk’s
FS(field separator) variable in the script, which you can put in a file: