There are several answers on this site about how to capture text between two patterns and print out each group, but I am interested only in the last group. I am doing this on Mac, not Linux.
My output comes from echo "" | openssl s_client -showcerts -connect oidc.eks.us-east-1.amazonaws.com:443 2>&1 |\
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p;/-END CERTIFICATE-/a\'
and I want to grab the last cert, between -----BEGIN CERTIFICATE-----
and -----END CERTIFICATE-----
inclusive.
To generalize, in text like
start
a
b
c
end
start
d
e
f
end
start
g
h
i
end
how can I just get
start
g
h
i
end
The reason I need this is because I need to get the last cert in a chain to get its thumbprint via openssl x509 -fingerprint -noout
to create an AWS OIDC provider programatically.