sed - Separate date and time with a comma -
i have access log 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 date , time separated comma using sed
seems want this,
$ sed 's/\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\) \([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)/\1,\2/g' file http://***.com ,**.**.**.**,2013-06-07,12:03:58 ,mozilla/5.0 (windows nt 6.1; wow64; rv:21.0) gecko/20100101 firefox/21.0.
\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)
capture date string.match in-between space character.
\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)
capture time string.- then replace matched strings
\1
characters inside group index 1,,
\2
characters inside group index 2. \(\)
called capturing group in basic regular expressions. example\([0-9]\{4\}\)
capture 4 digit number group.
Comments
Post a Comment