Skip to main content

How to Convert a Certificate to One Line Format For CLI/API Operations (KBA6669)




KBA# 6669

Applicable Delphix Versions

Click here to view the versions of the Delphix engine to which this article applies
Major Release All Sub Releases




5.0,,,,,,,,, ,,,,,


4.2,,,,,,, ,,


How to Task

Although the Delphix GUI allows for multiple line input text boxes for certificate installation (HTTPS certificate replacement, truststore installation, or password vault configuration), it may be desirable to leverage CLI or API functions to complete this configuration. As such, the formatting of JSON data for API input requires that certificates or private keys be entered as a single line. JSON does not support multiple line input. This requires that the existing line breaks be removed and replaced with \n text to indicate a line break (linefeed).


The certificate(s) and private key(s) desired for installation are expected be in PEM format (Base64 ASCII encoded).

Convert to one line - UNIX/Linux

A simple awk command can be leveraged to make the replacement:

awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' <certificate name>

This awk command subfunction removes each line break (\r), and prints output without new line, adding \n text after each line read, ultimately generating a single line output. This can optionally be redirected to a file as desired.



After (output severely abbreviated to illustrate single-line with \n text desired):


The subsequent output can then be entered in the relevant REST API POST field.


Convert to one line - Windows

If additional software installation is available, a Windows administrator may leverage Cygwin, which installs a collection of GNU and Open Source tools for Windows users. Alternatively, Microsoft also provides a Linux Subsystem option for Windows 10 which adds a compatibility layer, allowing execution of Linux binaries.

If these options are unavailable, many common third party text editors offer advanced find/replace capabilities which can approximate the Unix/Linux process discussed above, though usually will take two steps.

The following example leverages Regular expression find/replace available in Notepad++.  



The methods expressed here are not exhaustive or necessarily the optimal solution. Delphix may not be able to provide equivalent methods for other applications; this example is provided for convenience using one of the most common third-party utilities.

After opening the original key or PEM file, CTRL-H to find/replace (or go to Search > Replace in menu bar). Add the character $ in the Find what: box, then add \\n in the Replace with: box. Search Mode selection must be Regular expression.


The $ character in a regular expression is the anchor at end of line; this will append it with \n text, but the text must be escaped with an additional \ for it to be added as text rather than encoding a Unix line break.

Once this is completed, each line should have \n appended:

Since the Join Lines option will include spaces, another find/replace will be performed using Regular expression, this time the Find will be \n and Replace with: will be left blank.

This find/replace will remove the actual end of line encoding and result in our desired one-line certificate or key with \n text inserted:


The subsequent output can then be entered in the relevant REST API POST field.