Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ashishjullia/50dccec669fdf086d6b544713bb439fa to your computer and use it in GitHub Desktop.
Save ashishjullia/50dccec669fdf086d6b544713bb439fa to your computer and use it in GitHub Desktop.
convert cert or key to single line with \n included
awk '{sub(/\r$/,""); printf "%s\\n", $0}' filename
This command reads a file line by line and converts it into a single, long string, using the literal characters \n as a separator.
It does two main things for every line it reads:
It Cleans: The sub(/\r$/,"") part finds and removes the invisible Windows "carriage return" character (\r) from the end of the line. If a line is already clean, this part does nothing.
It Joins: The printf "%s\\n", $0 part prints the cleaned line, followed immediately by the text \n. Because printf doesn't add a line break, all the lines get joined together into one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment