1
I have a **text file of 49633 lines** (txt file) with the following format:
-e Tue Mar 28 20:17:01 -03 2017
total used free shared buffers cached
Mem: 239956 126484 113472 4904 10292 52280
-/+ buffers/cache: 63912 176044
Swap: 496636 0 496636
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 113460 10292 52308 0 0 1706 67 532 828 15 10 74 1 0
-e Tue Mar 28 20:18:01 -03 2017
total used free shared buffers cached
Mem: 239956 132808 107148 4904 10796 54872
-/+ buffers/cache: 67140 172816
Swap: 496636 0 496636
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 107656 10796 54872 0 0 654 29 219 353 6 4 90 0 0
-e Tue Mar 28 20:19:01 -03 2017
total used free shared buffers cached
Mem: 239956 132136 107820 4904 10824 54892
-/+ buffers/cache: 66420 173536
Swap: 496636 0 496636
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 107776 10824 54892 0 0 400 19 147 243 3 2 94 0 0
I would like to extract the id value from the CPU field given a time interval. For example:
inicio=Mar 28 20:17:01
fim = Mar 28 20:19:01
would print:
data id
Mar 28 20:17:01, 74
Mar 28 20:18:01, 90
Mar 28 20:19:01, 94
I’m trying but I couldn’t write any lines of code other than:
#!/usr/bin/env python
F = open(“arquivo.txt”,”r”)
Could someone help?
Nor did you read the start and end date?
– Woss
@Anderson Carlos Woss: I could only read the file!
– Ed S
@Anderson Carlos Woss: I really don’t know!
– Ed S
The simplest output I see is to use regular expressions. Read about the library
re
, python native.– Woss