Remove newline from openssl base64 encode string?
24,410
I'm sure there's simpler ways to do it, but here I'm using awk with output record separator blank. Being there only one record separator, the result will be blank. Now, I can test if there is newline or not by running output to file and cat -A
that file to show metacharacters.
$ printf 'Hello World' | openssl base64 | awk 'BEGIN{ORS="";} {print}' > tester.txt
$ cat -A tester.txt
SGVsbG8gV29ybGQ=
As you can see, there is no $ sign at the end of that string, hence no new line.
Related videos on Youtube
Author by
user779848
Updated on September 18, 2022Comments
-
user779848 over 1 year
echo -n 'HelloWorld' | openssl base64 | pbcopy
That command give me a newline after paste it.
I thought the -n removed the newline but don't remove when use base64.
so how can get my output string without a newline?
-
muru almost 9 yearsIf the output is base64 encoded, what difference does a newline make? Anyway, you can just delete newlines using
tr
:echo -n ... base64 | tr -d '\n' | pbcopy
. Are you using OSX? -
user779848 almost 9 years1) I want avoid the newline because affect the output, I mean I need the output clean, I use base64 to create passwords, so when paste with newline of course give an alert of wrong password. 2) yes Im on OSX 3) now works with echo -n 'HelloWorld' | openssl base64 | tr -d '\n' | pbcopy
-
muru almost 9 yearsThen you're doing it wrong. No sane base64 decoder will care about newlines.
-
user779848 almost 9 yearsworks like this:
echo -n 'helloworld' | openssl base64 | tr -d '\n' | pbcopy
-
muru almost 9 yearsQuestions on OSX should be posted on Ask Different or Unix & Linux. (yes, that's how it works).
-
user779848 almost 9 yearsouch! sorry, Im new and can't find the mac channel, thank you; is possible move this or delete? well I got my answer thank you
-
Sergiy Kolodyazhnyy almost 9 yearsI'm voting to close this question as off-topic because OP uses software not found in Ubuntu but rather in Mac OS X
-
redochka over 6 years@muru in a telnet session (while debugging) the new line will trigger data sending
-
Jason Ryan Taylor about 5 yearsthis is actually pretty simple if you use printf:
-
Jason Ryan Taylor about 5 yearsecho "some long string" | base64 | while read line; do printf $line; done
-
-
Fabby over 8 yearsAs you're a reputation 1 user: If this answer helped you, don't forget to click the grey ☑ at the left of this text, which means Yes, this answer is valid! ;-)