Question

I have a shell script which parses the aws cloudfront log.

awk '{print $1","$2","$4","$5","$8","$9","(substr($11,1,7))","$12 }' access_log | grep cid= | sed -e 's/\/data//g;s/\/videos//g;s/\/images//g;s/\/hls//g;s/\/rss//g;s/\/xml//g;s/cid=//g' > stats.txt

I am trying to combine fields $1 and $2 so the date time stamp resembles this format: Date_time 0000-00-00 00:00:00

It is currently in two fields date, time 2012-12-23 20:59:47

Any help is appreciated.

Was it helpful?

Solution

The awk portion of your script is adding a comma between the date and time portions of what you want to be formatted as datetime. This is causing "YYYY-MM-DD HH:MM:SS" to appear as "YYYY-MM-DD,HH:MM:SS".

To get the result you're after change your script to:

awk '{print $1" "$2","$4","$5","$8","$9","(substr($11,1,7))","$12 }' access_log | grep cid= | sed -e 's/\/data//g;s/\/videos//g;s/\/images//g;s/\/hls//g;s/\/rss//g;s/\/xml//g;s/cid=//g' > stats.txt

This should insert into the datetime field correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top