Filtering and extracting fields from a text file in python -
i have text file in following format.
03/12 20:23:26.11: 04:23:26 l9 <mx acc magnum xdv:00111a0000000117 00d3001200870172 01ff6000f01cfe81 3d26000000000300 03/12 20:23:26.11: 04:23:26 l9 <mx acc mid 0x1500 len 26 xdv:00111a0000000117 00d3001200870172 01ff6000f01cfe81 3d26000000000300 03/12 20:23:26.11: 04:23:26 l8 <mx jk31 (mx) jsp:17.37.6.99: size = 166, data: 00345c4101003031 e463ef0113108701 5a01ff6008f01cfe 81ab170000000003 ef01131087015a01 ff6008f01cfe81ab 170000000003ef01 131087015b01ff60 00f01cfe81701b00 00000003ef011310 87015b01ff6000f0 1cfe81701b000000 0003ef0113108701 5c01ff2000f01cfe 81cb240000000003 ef01131087015c01 57cc00f01cfe81cb 240000000003ef01 131087015d01ff20 00f01cfe815b2900 00000003ef011310 87015d01ff2000f0 1cfe815b29000000 0003ef0113108701 5e01ff6000f01cfe 819d280000000003 ef01131087015e01 ff6000f01cfe819d 0003 03/15 20:23:26.11: 04:23:26 l8 <kx jk49 (kx) jsp:15.33.2.93: size = 163, data: 00647741000030ef 01131087015a01ff 6008f01cfe81ab17 0000000003ef0113 1087015a01ff6008 f01cfe81ab170000 000003ef01131087 015b01ff6000f01c fe81701b00000000 03ef01131087015b 01ff6000f01cfe81 701b0000000003ef 01131087015c01ff 2000f01cfe81cb24 0000000003ef0113 1087015c01ff2000 f01cfe81cb240000 000003ef01131087 015d01ff2000f01c fe815b2900000000 03ef01131087015d 01ff2000f01cfe81 5b290000000003ef 01131087015e01ff 6000f01cfe819d28 0000000003ef0113 1087015e01ff6000 f01cfe819d280000 a6220000000003 03/15 20:23:26.11: 04:23:26 l8 <kx jk21 (kx) jsp:10.22.1.53:size = 163, data: 009d1141000030ef 01131087015a01ff 6008f01cfe81ab17 0000000003ef0113 1087015a01ff6008 f01cfe81ab170000 000003ef01131087 015b01ff6000f01c fe81701b00000000 03ef01131087015b 01ff6000f01cfe81 701b0000000003ef 01131087015c01ff 2000f01cfe81cb24 0000000003ef0113 1087015c01ff2000 f01cfe81cb240000 000003ef01131087 015d01ff2000f01c fe815b2900000000 03ef01131087015d 01ff2000f01cfe81 5b290000000003ef 01131087015e01ff 6000f01cfe819d28 0000000003ef0113 1087015e01ff6000 f01cfe819d280000 a6220000000003
i want extract line line of file apply filter on it.for example want extract lines have l8 <mx jk31 (mx)
in it, extract time (04:23:26
) , size (166
) , plot graph of size on time. want in python.
# !/usr/bin/env python # -*- coding: utf-8 -*- match = ("l8 <mx jk31 (mx)") open("test.txt") fin: print(' : {}', fin.name) line in fin: if match in line: print(line)
i able extract lines expected text.(if match in line:
).how extract time field , size field in python?
you extract time , size this:
# !/usr/bin/env python # -*- coding: utf-8 -*- match = ("l8 <mx jk31 (mx)") open("test.txt") fin: print(' : {}', fin.name) line in fin: if match in line: line = line.strip.split() time = line[2] size = line[9].strip(",")
Comments
Post a Comment