Today in the forum to see a question on the note down, respectively, with SED and python to write the answer, when it is the re module of the small exercise bar
2014-11-05 09:39:48:ip[192.168.10.152] logid[281424076]
2014-11-05 09:58:33:ip[192.168.10.152] logid[393876725]
2014-11-05 09:58:33:ip[192.168.10.152] logid[393883438]
2014-11-05 09:58:34:ip[192.168.10.152] logid[394052520]
2014-11-05 09:58:34:ip[192.168.10.152] logid[394057519]
the 2nd column takes the last colon, and the 3rd and 4th columns the contents of the square brackets.
Sed:
Sed ' s/://;s/ip\[\ (. *\) \]/\1/;s/\].*\[//' Test
Python:
#!/usr/bin/env pythonimport refile = open (' Test ') done = 0while not Done: line = file.readline () if line != ': line = line.strip (' \ n ') this_line_list = line.split (' ') zz1 = re.compile (' [0-9]{2}:[0-9]{2}:[0-9]{2} ') zz2 = re.compile (' [0-9]{1,3}.[ 0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3} ') zz3 = re.compile (' [0-9]{1,} ') &NBsp; pp1 = Re.findall (zz1,this_line_list[1]) pp2 = re.findall (zz2,this_line_list[2]) pp3 = re.findall (Zz3,this_line_list[3]) print '%s %s %s %s ' % (this_line_list[0],pp1[0],pp2[0],pp3[0]) else: done = 1file.close ()
This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1574944
Python RE Module small example