Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

text - tr -d or sed -e 's/ //g' can't remove CRLF from file in MINGW32

i have this CERTIFICATE file enter image description here

-----BEGIN CERTIFICATE REQUEST-----
MIIFIDCCAwgCAQAwIDEeMBwGA1UEAwwVdmF1bHQudmF1bHQtcGVyc28uc3ZjMIIC
IjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA2h1Io+IPgBFYa+L9TFQ3hXDk
dKJFHVBHFx6RaYMDHJe75c/Ozq3zwAwlDlPviTvB96OyuBX9KIBDk5b0QCELYHym
omCSm1GO+Izxgu26aBvrbgycwUml+lXqW8R6reMpEBnaIRgOvPhIsncaR3iQBt8m
yPo/v5ouPCrVGJ5Hehi4ll0vwxI5/ETlJIjnDqBODwWRLvktv4ysHRj/4hyh5Yn0
IalOn9Cxo0w2zVQhFE63n3enz7c=
-----END CERTIFICATE REQUEST-----

i try to remove all the CRLF from the file

like this also tried tr -d " " and tr -d " " :

cat <<EOF >${TMPDIR}/csr.yaml
apiVersion: certificates.k8s.io/v1beta1
kind: CertificateSigningRequest
metadata:
 name: ${CSR_NAME}
spec:
 groups:
 — system:authenticated
 request: $(cat ${TMPDIR}/server.csr | base64 | sed -e 's/
//g')
 usages:
 — digital signature
 — key encipherment
 — server auth
EOF

no matter what i do the end result file the part of the CERTIFICATE content is still contains the line break How can i remove it ? enter image description here

question from:https://stackoverflow.com/questions/65844547/tr-d-or-sed-e-s-r-g-cant-remove-crlf-from-file-in-mingw32

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try:

cat -v file.csr | tr "^M" "
" | tr -d "
"

This will output the file with Windows file endings (-v) before using tr to replace the file endings (^M) with a new line and then delete the new lines (-d)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...