Given a file containing web access logs for a YouTube video, every line is a hit and is in the format. 62.172.72.131 - - [02/Jan/2003:02:06:41 -0700] GET /random/html/riaa_hacked/ HTTP/1.0 200 10564 - Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; WWP 17 August 2001)    63.194.21.74 - - [30/Apr/2003:13:13:22 -0700] GET /random/video/Star_Wars_Kid_Remix.wmv HTTP/1.1 206 1146708 - NSPlayer/9.0.0.2980 WMFSDK/9.0    161.114.88.73 - - [02/May/2003:03:27:41 -0700] GET /random/video/Star_Wars_Kid.php HTTP/1.0 302 1 http://friends.portalofevil.com/sp.php?si=3&fi=FRIENDSOF&ti=1000489621&pi=1000489621 Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; compaq)    64.164.63.70 - - [02/May/2003:13:24:19 -0700] GET /random/video/Star_Wars_Kid.wmv HTTP/1.1 302 307 http://blogdex.media.mit.edu/ Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)I need to extract the IP address and Date in the square bracket and put it in a csv file i.e ip_address,dateI'm using the following commands to get the IP and Date respectivelygrep -oP '([0-9]{1,3}\.){3}[0-9]{1,3}' test.loggrep -oP \[\K[^\]]+ test.logI don't know how to combine it into 1 string to put it in a csv tr '\n' > file.csvSince this is a large log file, I thought unix commands will deal with it efficiently. Is there a difference between using unix commands or programming it in python (reading each line, manipulate the string and then write to file)?
Extract Strings from Web Log file
sed;grep;regular expression;logs;python