I have access log with lines
http://***.com ,**.**.**.**,2013-06-07 12:03:58 ,Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0.
I need the date and time to be separated by a comma using sed
I have access log with lines
http://***.com ,**.**.**.**,2013-06-07 12:03:58 ,Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0.
I need the date and time to be separated by a comma using sed
A bit secure in a complicated sed
sed 's/\(,[-0-9]\{10\}\) *\([0-9:]\{8\},\)/\1,\2/g' YourFile
A bit easy in a very complicated sed vs a simple awk
sed 's/ */,/' YourFile
but in both case (as earlier reply post) it assumes that there is only line like the sample in the file.If not you have to give the other possible file (as a http log , any error taht can occure like bad URL message, ... )
Seems like you want something like this,
\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)
Capture the date string.Match the in-between space character.
\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)
Capture the time string.\1
characters inside group index 1,,
\2
characters inside group index 2.\(\)
called capturing group in Basic regular expressions. So for example\([0-9]\{4\}\)
would capture the 4 digit number into a group.