Python 从大型文本/dat文件中提取字符串/值
我想从文本模式如下的文本文件中提取“Drops:XXXXX”:Python 从大型文本/dat文件中提取字符串/值,python,regex,awk,grep,pattern-matching,Python,Regex,Awk,Grep,Pattern Matching,我想从文本模式如下的文本文件中提取“Drops:XXXXX”: Pkts: 215104502 Bytes: 202537648280 Drops: 1302599 Pkts: 55330252 Bytes: 52018951784 Drops: 22086 Pkts: 46226143 Bytes: 42980694784 Drops: 0 Pkts: 52931264 Bytes: 49764764008 Drops: 0 Pkts: 60616843 Bytes:
Pkts: 215104502 Bytes: 202537648280 Drops: 1302599
Pkts: 55330252 Bytes: 52018951784 Drops: 22086
Pkts: 46226143 Bytes: 42980694784 Drops: 0
Pkts: 52931264 Bytes: 49764764008 Drops: 0
Pkts: 60616843 Bytes: 57773237704 Drops: 1280513
Pkts: 215104502 Bytes: 202537648280 Drops: 1302599.
我对任何模式搜索方法开放(grep、awk、python)
谢谢在谷歌上搜索几分钟,你就会发现你需要正则表达式,而ansewr会是这样的
re.search(r'(?<=Drops: )\d+', input_string).group(0)
re.search(r'(?使用awk
您可以执行以下操作:
awk '{ print $5, $6 }' text
grep“^Drops:\t\d”xxx.txt