简体   繁体   中英

Need to parse the output of linux command

I have the output of the linux command as below:

/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"}

I need to only filter this hash file :

{: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"} 

and write to another file.

I tried the 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))

I get this exception.How to do it?

This should be a simple re problem.

import re

command = 'grep -rwn /auto/qalogs/branch_team_5.7/ert/hash_list/ -e ' + alist[0] + ''
filter  = '/auto/qalogs/branch_team/drt/hash_list/enc_options_rkm_ekm.rb'    

log = subprocess.subprocess.getoutput(command)

with open('output.txt', 'w+') as f:
    for message in log:
        if re.search(filter, message):
            f.write(result)

Unfortunetly, I don't have more sample data to really vet it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM