Search line by line (按行搜索)

需求:

查找多行中含有sshd的行


Python:

import re

subject = '''build    22873  0.0  0.0 138964  2348 ?        S    10:29   0:00 sshd: build@pts/0   
... build    22874  1.2  0.0  28320  9564 pts/0    Ss   10:29   0:00 -bash
... build    22997  0.0  0.0   4400   612 ?        S    10:29   0:00 /bin/sh -xe /tmp/hudson3230150410476111992.sh
... build    22999  0.2  0.0  39492  3096 ?        Sl   10:29   0:00 expect /home/build/3290/release/pica8/build.tcl build /home/build/3290/release/pica8/branche
... build    23002  0.0  0.0  41528  2884 pts/1    Ss+  10:29   0:00 ssh build@10.10.50.16
... root     23005  0.4  0.0 136744  6224 ?        Ss   10:29   0:00 sshd: build [priv]  
... build    23130  0.0  0.0 136744  2324 ?        S    10:29   0:00 sshd: build@pts/22  
... build    23131  8.6  0.0  28312  9548 pts/22   Ss   10:29   0:00 -bash
... build    23251  1.2  0.0 118504  3696 pts/22   D+   10:29   0:00 svn cleanup ../../sdk/sdk-xgs-robo-6.'''

lines = re.split("\r?\n", subject)

reobj = re.compile("sshd")

for line in lines[:]:

    if reobj.search(line):

        print '%s match!' % line

    else:

        print '%s no match!' % line

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值