Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从大型文本/dat文件中提取字符串/值_Python_Regex_Awk_Grep_Pattern Matching - Fatal编程技术网

Python 从大型文本/dat文件中提取字符串/值

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:

我想从文本模式如下的文本文件中提取“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: 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