Given that you don't want a general solution, i.e. you're looking for a hack and don't desire a robust solution, this seems pretty hack-ish and yet produces the right output, at least if the sample input you give is the most complex case you can reasonably encounter:
#!/usr/bin/env bash
set -o posix
grep '^[[:blank:]]Issuer:' |
sed -Ee 's/^. O[[:blank:]]=[[:blank:]]("[^"]"|[^",]),.*/\1/'
Even as a hack, I'm certain this could be improved, if one had the need.
The above is nearly POSIX-compliant, and runs on my non-GNU system.
$ grep -w Issuer: /usr/local/etc/ssl/cert.pem | head -5; \
echo '...'; grep -w Issuer: /usr/local/etc/ssl/cert.pem | tail -5
Issuer: C = ES, O = FNMT-RCM, OU = AC RAIZ FNMT-RCM
Issuer: C = ES, O = FNMT-RCM, OU = Ceres, organizationIdentifier = VATES-Q2826004J, CN = AC RAIZ FNMT-RCM SERVIDORES SEGUROS
Issuer: CN = ACCVRAIZ1, OU = PKIACCV, O = ACCV, C = ES
Issuer: C = IT, L = Milan, O = Actalis S.p.A./03358520967, CN = Actalis Authentication Root CA
Issuer: C = US, O = AffirmTrust, CN = AffirmTrust Commercial
...
Issuer: C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust ECC Certification Authority
Issuer: C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust RSA Certification Authority
Issuer: C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 1999 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 1 Public Primary Certification Authority - G3
Issuer: C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 1999 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 2 Public Primary Certification Authority - G3
Issuer: C = US, OU = www.xrampsecurity.com, O = XRamp Security Services Inc, CN = XRamp Global Certification Authority
$ ./test.sh < /usr/local/etc/ssl/cert.pem | head -5; \
echo '...'; ./test.sh < /usr/local/etc/ssl/cert.pem | tail -5
FNMT-RCM
FNMT-RCM
ACCV
Actalis S.p.A./03358520967
AffirmTrust
...
The USERTRUST Network
The USERTRUST Network
"VeriSign, Inc."
"VeriSign, Inc."
XRamp Security Services Inc
csvtool
andmiller
. – AdminBee Nov 09 '21 at 15:28openssl x509 -issuer -noout
, see also the-nameopt
option there. Like:openssl x509 -noout -nameopt sep_multiline,utf8,esc_ctrl -issuer
to make it easier to parse. – Stéphane Chazelas Nov 09 '21 at 22:34