Issue
I have to convert RSA private key to one-line to store in the password manager (Passwordstate). I used tr -d '\n' < id_rsa
to convert to single line and cat id_rsa.line | sed -e "s/-----BEGIN RSA PRIVATE KEY-----/&\n/" -e "s/\S\{64\}/&\n/g"
to convert back to original multi-line.
Conversion back to multi-line worked on Ubuntu, but not on Mac. Why this doesn't work on Macbook
Solution
Please try:
LF=$'\\\x0A'
cat id_rsa.line | sed -e "s/-----BEGIN RSA PRIVATE KEY-----/&${LF}/" -e "s/-----END RSA PRIVATE KEY-----/${LF}&${LF}/" | sed -e "s/[^[:blank:]]\{64\}/&${LF}/g"
or
LF=$'\\\x0A'
cat id_rsa.line | sed -e "s/-----BEGIN RSA PRIVATE KEY-----/&${LF}/" -e "s/-----END RSA PRIVATE KEY-----/${LF}&${LF}/" | fold -w 64
Non-GNU sed
does not interpret "\n" in the replacement as a newline.
As a workaround, you can assign a variable to a newline and embed it in the replacement.
Note that I've kept the UUC for readability :P.
Answered By - tshiono Answer Checked By - Marilyn (WPSolving Volunteer)