0
我有linux命令下面的輸出:需要解析linux命令的輸出
/auto/qalogs/branch_team_5.7/drt/hash_list/bk20170401/audit-gc.rb:11:{:component=>"Encryption", :params=>"-f /auto/qalogs/branch_team/drt/hash_list/enc_options_rkm_ekm.rb log_level=debug", :script=>"encryption/destroy.rb", :timeout=>10800, :skipcheckconnection=>1, :minlimitver=>"5.3.0.0"}
/auto/qalogs/branch_team_5.7/drt/hash_list/bk20170401/encryption-audit-gc-part1.rb:11:#{:component=>"Encryption", :params=>"-f /auto/qalogs/branch_team/drt/hash_list/enc_options_rkm_ekm.rb log_level=debug", :script=>"encryption/destroy.rb", :timeout=>10800, :skipcheckconnection=>1, :minlimitver=>"5.3.0.0"}
Binary file /auto/qalogs/branch_team_5.7/ert/hash_list/.encryption-audit-gc.rb.swp matches
/auto/qalogs/branch_team_5.7/ert/hash_list/encryption-audit-gc.rb:11:{:component=>"Encryption", :params=>"-f /auto/qalogs/branch_team/drt/hash_list/enc_options_rkm_ekm.rb log_level=debug", :script=>"encryption/destroy.rb", :timeout=>7200, :skipcheckconnection=>1, :minlimitver=>"5.3.0.0"}
我只需要過濾此散列文件:
{:component=>"Encryption", :params=>"-f /auto/qalogs/branch_team/drt/hash_list/enc_options_rkm_ekm.rb log_level=debug", :script=>"encryption/destroy.rb", :timeout=>7200, :skipcheckconnection=>1, :minlimitver=>"5.3.0.0"}
,並寫入到另一個文件。
我試過followng:
out=subprocess.getoutput('grep -rwn
/auto/qalogs/branch_team_5.7/ert/hash_list/ -e '+alist[0]+'')
print ("output of grep is", out)
pattern=re.compile(r'(/auto/qalogs/branch_team_5.7/ert/hash_list/.*.rb:\d)
(\:)(\{.*\})',out)
print (pattern.groupobject(0))
我得到這個exception.How辦呢?
你應該看看're'文件以瞭解如何使用它 – Morb
爲什麼你使用'subprocess(grep ...'?爲什麼不只使用'module re'? – stovfl
我想如果你可以做一點點更清楚你要輸入到正則表達式中的輸入內容,你想要匹配的字符串,以及你想要獲得的組,我能夠幫助的人。 –