在代码中,我正在搜索以FAILED
开头的字符串。
tt
变量保存subprocess.Popen
的stdoutput。
我尝试过re.serach
&;re.match
,但它产生{
#!/usr/bin/python
import subprocess
import re
def cbk():
with open('GDPC.txt', 'r') as f:
for line in f:
tt = subprocess.Popen(['/grid/it/bin/cyberarksdk.sh' , 'chk', line], stdout=subprocess.PIPE).communicate()[0]
#pat_match=re.search(".*FAILED:\s+", tt)
pat_match=re.search(r'(^FAILED:)\s+', tt)
print pat_match
cbk()
^{pr2}$Output of the above script:
The output of the Variable
tt
:
FAILED: Account/host myserver1 does not exist inside cyberark.
1 102_2923 DS-KS-DEFAULT-UNIX-ROOT Operating System-DS-Unix-RootAccounts-SSH-myserver2-root
意图:只需搜索以FAILED
字符串开头的行,并剪切第三列myserevr1并放入文件file1
,类似地,任何以1
开头的行都将myserver2
剪切并放入另一个文件file2
。在
注意:GDPC.txt
包含服务器名称。在
我现在得到的解决方案是得到包含
^{pr2}$FAILED
的行使用split()和splitlines()(将字符串转换为行列表,将行列表转换为列列表,然后根据需要为这些列编制索引):
相关问题 更多 >
编程相关推荐