-3

I want to extract the "Drops: XXXXX" from a text file whose text pattern looks something like this:

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.

I am open to any pattern searching methodolofy ( grep,awk,python)

Thanks

4

2 回答 2

3

谷歌搜索几分钟会发现你需要正则表达式,而答案类似于

re.search(r'(?<=Drops: )\d+', input_string).group(0)
于 2013-01-02T20:50:12.287 回答
1

awk可以这样做:

awk '{ print $5, $6 }' text
于 2013-01-02T20:58:26.043 回答