How can I convert a file with multiple lines to a string with n
characters in bash?
For example – I have a certificate that I need to configure in my configuration JSON
file
so instead of having
-----BEGIN CERTIFICATE----- MIIDBjCCMIIDB MIIDBjCCMIIDB .... MIIDBjCCMIIDB== -----END CERTIFICATE-----
I will have
-----BEGIN CERTIFICATE-----nMIIDBjCCMIIDBnMIIDBjCCMIIDBn....nMIIDBjCCMIIDB==n-----END CERTIFICATE-----
Advertisement
Answer
One way using awk
:
$ awk '$1=$1' ORS='\n' file -----BEGIN CERTIFICATE-----nMIIDBjCCMIIDBnMIIDBjCCMIIDBn....nMIIDBjCCMIIDB==n-----END CERTIFICATE-----n