If you need to copy and paste base64 encoded certificate data into yaml. How wou . . .

Alex Novik:
If you need to copy and paste base64 encoded certificate data into yaml.
How would you do that without getting carriage returns and spaces every line?

I am currently doing it this way: cat user.crt | base64
Then paste in vi
then I have to remove \n and \s
so i do:
:%s/\n*//g
:%s/\s*//g
This is inconvinient because I have to paste in separate file for it to work
Removing \n and \s from terminal ouput with sed for some reason does not work

How to avoid this? Please advice

Jesus Arechiga Jimenez:
don’t copy, pass the value

Jesus Arechiga Jimenez:
or try cat user.crt | base64 -n

Alex Novik:
no such option as base64 -n but I found this in man base64
-w, --wrap=COLS wrap encoded lines after COLS character (default 76).
Use 0 to disable line wrapping
So when I did:
cat /etc/kubernetes/pki/ca.crt | base64 --wrap=0
It works! I appreciate you help @Jesus Arechiga Jimenez

Jesus Arechiga Jimenez:
Awesome!

Alex Novik:
Before:

controlplane $ cat /etc/kubernetes/pki/ca.crt | base64         
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCVENDQWUyZ0F3SUJBZ0lJYytPeDVlWDFi
eGd3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVG
dzB5TXpFd01UY3hOREkzTlRKYUZ3MHpNekV3TVRReE5ETXlOVEphTUJVeApFekFSQmdOVkJBTVRD
bXQxWW1WeWJtVjBaWE13Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLCkFvSUJB
UUNvbXVQVHBBNG90THZmRzhMT0lUVG9paERGS2Z0c3hicHJhUDFYNFY1aFQwUG5pRGZWZk5lSzJm
ZUcKZVdEU0ZNZDZmZGRTTFJPY3RDTFhveUNCRE9sQk5XMlZleENwWGk3R2dYSzc0TXMzVXRZcHVJ
UG1rSHg5cjliawo3Ujd2ZE5TVTh4dGdLek9qUERTbmVWYnhZUVQwWDVGWGpCZG1XWmJEcE9LRzU3
MEN3Ym1BS21QcEpHOHhrNTFFCkhBSUp0SDl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