我有如下的python脚本输出
client:"A"
Total number of keys discovered: 22
Execution finished. Total time: 0:00:05.361506
Key: 'caJ8ArNRvefgdfgbdhfdbfdbf' | Cannot flip key due to
feature1 being enabled
Key: 'caixF0Nmdfjdfdbfdgdbgdnmjdfs' | Cannot flip key due to
feature1 being enabled
Total keys: 22 | Keys that Application can serve: 20 | Keys that Application can't serve: 2
Execution finished. Total time: 0:00:33.796226
client:"B"
Total number of keys discovered: 13
Execution finished. Total time: 0:00:05.539271
Total keys: 13 | Keys that Application can serve: 13 | Keys that Application can't serve: 0
Execution finished. Total time: 0:00:20.573984我想在python脚本中使用"Keys that Application‘t serve: 2“这个数字,我想要一些东西来帮助我对无法提供的键数进行grep,并将其用作脚本中的变量
发布于 2020-12-25 06:08:03
假设您的输出是一个文本文件。
$ cat output.txt
# client:"A"
# Total number of keys discovered: 22
# Execution finished. Total time: 0:00:05.361506
# Key: 'caJ8ArNRvefgdfgbdhfdbfdbf' | Cannot flip key due to
# feature1 being enabled
# Key: 'caixF0Nmdfjdfdbfdgdbgdnmjdfs' | Cannot flip key due to
# feature1 being enabled
# Total keys: 22 | Keys that Application can serve: 20 | Keys that Application can't serve: 2
# Execution finished. Total time: 0:00:33.796226
# client:"B"
# Total number of keys discovered: 13
# Execution finished. Total time: 0:00:05.539271
# Total keys: 13 | Keys that Application can serve: 13 | Keys that Application can't serve: 0
# Execution finished. Total time: 0:00:20.573984然后,您可以使用awk并运行以下代码行来获得所需的输出。
awk 'BEGIN { FS = ":" } /client/ { print $2 } /serve/ { print $NF }' output.txt > client.txt
cat client.txt
# "A"
# 2
# "B"
# 0然后,您可以使用client.txt文件并将其读取到Python中,如下所示。
with open('client.txt') as fh:
for line in fh.readlines():
print(line.replace('\"', '').strip())
# A
# 2
# B
# 0https://stackoverflow.com/questions/65433731
复制相似问题