You need to extract percent first, and then filter the lines basing on that.
import re
def extract_percent(line):
# doing extraction
try:
return int(re.findall('[0-9]+%', line)[0][:-1])
except:
return 0
print [line for line in lines if extract_percent(line) > 85]
If nothing is found, 0 is returned.
Otherwise is returned the number before %
.
If you have several percent numbers in the string, the first one is returned.
It can become a little bit trickier if the percent can be float,
but it is not so hard also. Just play with the regular expression [0-9]+%
.
If the position is fixed (fifth column), you can rewrite the extract_percent
function this way:
def extract_percent(line):
try:
return int(line.split()[4][:-1])
except:
return 0
re
module) to extract the digits before the%
. convert them to an integer and see if it is greater than 85.