Я пытаюсь заменить содержимое файла crt
и заменить строку в файле json на извлеченное содержимое crt, вот что я сделал:
Содержимое файла сертификата:
-----BEGIN CERTIFICATE-----
MIICNTCCAdygAwIBAgIRALrbz2i0JY1TqgQkKLp9dxEwCgYIKoZIzj0EAwIwbDEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRowGAYDVQQDExF0bHNjYS5l
eGFtcGxlLmNvbTAeFw0xODA1MjMwNDM0MDBaFw0yODA1MjAwNDM0MDBaMGwxCzAJ
BgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJh
bmNpc2NvMRQwEgYDVQQKEwtleGFtcGxlLmNvbTEaMBgGA1UEAxMRdGxzY2EuZXhh
bXBsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASr/tmDhbly94C52F1M
O8CvZdDupDB7sfofihmDg0xsrdfpFy3ylZ4NO5vCfOMIxM/uhLarO8p8uuWNm9iP
oDWSo18wXTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMB
Af8EBTADAQH/MCkGA1UdDgQiBCCCjhsPikle31Kv3ixPqFwL/08aOLU5wb7s7Ucf
RUJLEDAKBggqhkjOPQQDAgNHADBEAiAV/SzA9A7DgONfAbnlaVZzA8ZWcovPp5zI
JYCvxDO8/AIgIj2J6hOpgXxbeuO9kF+srpkwKE8Z1/5Efwd73nMcsvo=
-----END CERTIFICATE-----
Содержимое файла template.json:
{
"cert": "CERT"
}
test.sh
# Fetching cert.crt content and storing in CERT variable
CERT=$(cat cert.crt)
# Converting cert to single line string by replacing newline with \n
CERT=$(echo "${CERT//$'\n'/\n}")
# Trying to replace CERT string in template.json and store the updated json in test.json
sed -e "s/_CERT_/${CERT}/g" template.json > test.json
При выполнении сценария появляется следующая ошибка:
sed: 1: "s/ORDERER_CA_CERT/----- ...": bad flag in substitute command: 't'
Ожидаемый результат
{
"cert": "-----BEGIN CERTIFICATE-----\nMIICNTCCAdygAwIBAgIRALrbz2i0JY1TqgQkKLp9dxEwCgYIKoZIzj0EAwIwbDEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRowGAYDVQQDExF0bHNjYS5l\neGFtcGxlLmNvbTAeFw0xODA1MjMwNDM0MDBaFw0yODA1MjAwNDM0MDBaMGwxCzAJ\nBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJh\nbmNpc2NvMRQwEgYDVQQKEwtleGFtcGxlLmNvbTEaMBgGA1UEAxMRdGxzY2EuZXhh\nbXBsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASr/tmDhbly94C52F1M\nO8CvZdDupDB7sfofihmDg0xsrdfpFy3ylZ4NO5vCfOMIxM/uhLarO8p8uuWNm9iP\noDWSo18wXTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMB\nAf8EBTADAQH/MCkGA1UdDgQiBCCCjhsPikle31Kv3ixPqFwL/08aOLU5wb7s7Ucf\nRUJLEDAKBggqhkjOPQQDAgNHADBEAiAV/SzA9A7DgONfAbnlaVZzA8ZWcovPp5zI\nJYCvxDO8/AIgIj2J6hOpgXxbeuO9kF+srpkwKE8Z1/5Efwd73nMcsvo=\n-----END CERTIFICATE-----"
}