【发布时间】:2018-03-04 13:13:06
【问题描述】:
我从正在分析网站上的证书的程序中导出以下字符串,这将是错误修复分析的一部分
CERT_SUMMARY:127.0.0.1:127.0.0.1:631:sha256WithRSAEncryption:
/O=bfcentos7-test/CN=bfcentos7-test/emailAddress=root$bfcentos7-
test:/O=bfcentos7-test/CN=bfcentos7-test/emailAddress=root$bfcentos7-
test:170902005715Z:270831005715Z:self signed certificate
(将上面的输出视为单行)
我需要的是在 bash shell 中提取sha256WithRSAEncryption 的最佳方法。这可以是 sha384withRSAEncryption 之类的任何东西或其他东西。
在CERTSUMMARY 之后,它总是在其端口631 之上的127.0.0.1:127.0.0.1:portnum,但它可以是任何东西。
这在系统内部运行并返回此字符串以及 SSL 或 TLS(未图示)
这是另一个返回的例子
CERT_SUMMARY:127.0.0.1:127.0.0.1:52311:sha256WithRSAEncryption:
/CN=ServerSigningCertificate_0/name=Type`Administrator
/name=DBName`ServerSigningCertificate_0:/C=US/CN=BLAHBLAH/
ST=California/L=Address, Emeryville CA 94608/O=IBM BigFix Evaluation
License/OU=Customer/emailAddress=blahblay@gmail.com/name=
Hash`sha1/name=Server`bigfix01/name=CustomActions`Enable
/name=LicenseAllocation`999999/name=CustomRetrievedProperties`Enable:
170702212459Z:270630212459Z:unable to get local issuer certificate
提前致谢。 shell编程的新手,但正在学习!
【问题讨论】:
-
“提取”是什么意思?您想知道
sha256WithRSAEncryption或sha384withRSAEncryption是否在字符串中,或者您想提取该字符串后面的值?请澄清。 -
你还记得this发帖吗?
-
是的.. 我想提取 sha256WithRSAEncryption 或文本该部分中的任何值
-
awk -F ":" '/CERT_SUMMARY/ {print $5}' file? -
@cyrus 真的像用 awk 选对列一样简单吗?
标签: string bash parsing awk grep