加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Search line by line (按行搜索)

发布时间:2020-12-14 01:44:44 所属栏目:百科 来源:网络整理
导读:需求: 查找多行中含有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 /bi

需求:

查找多行中含有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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读