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.

Share:
24,410

Related videos on Youtube

user779848
Author by

user779848

Updated on September 18, 2022

Comments

  • user779848
    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
      muru almost 9 years
      If 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
      user779848 almost 9 years
      1) 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
      muru almost 9 years
      Then you're doing it wrong. No sane base64 decoder will care about newlines.
    • user779848
      user779848 almost 9 years
      works like this: echo -n 'helloworld' | openssl base64 | tr -d '\n' | pbcopy
    • muru
      muru almost 9 years
      Questions on OSX should be posted on Ask Different or Unix & Linux. (yes, that's how it works).
    • user779848
      user779848 almost 9 years
      ouch! 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
      Sergiy Kolodyazhnyy almost 9 years
      I'm voting to close this question as off-topic because OP uses software not found in Ubuntu but rather in Mac OS X
    • redochka
      redochka over 6 years
      @muru in a telnet session (while debugging) the new line will trigger data sending
    • Jason Ryan Taylor
      Jason Ryan Taylor about 5 years
      this is actually pretty simple if you use printf:
    • Jason Ryan Taylor
      Jason Ryan Taylor about 5 years
      echo "some long string" | base64 | while read line; do printf $line; done
  • Fabby
    Fabby over 8 years
    As 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! ;-)