The following command works for encoding stdin using echo:

echo "abc" | openssl enc -base64

This command also works for substituting characters in stdin using cat:

cat | sed 's/a/b/g'

However, the following command, which should encode stdin using cat does not meet my needs, because it doesn't display the encoded value every time I hit return.

cat | openssl enc -base64

How do I encode stdin on-the-fly using cat?

  • 1
    "Don't work" is not a very good problem description. – David Schwartz Apr 23 '13 at 4:09

If you type

cat | openssl enc -base64

and then press Ctrl+D then it will encode everything you just typed.

| improve this answer | |
  • While that works, I need a continues result. IE I keep typing and every time I hit return, I get an encoded value out – nick Apr 23 '13 at 6:06
  • @nick: If you want to get satisfactory answers, you should edit your question to add details like this. – Scott Aug 2 '13 at 22:33
  • 1
    @nick: to be clear, every time you press enter you want an encoded value just for that line of text, or for the entire body of text you've entered? – Nathan Nov 4 '13 at 20:08

First of all, you (just about) never need to use cat | or cat one_file |.  For example, your sed example works fine as

sed 's/a/b/g'

So my first suggestion is that you try

openssl enc -base64

without the cat.

But, honestly, I don’t expect that to work. You may need to get a little fancier:

while read x
      echo "$x" | openssl enc -base64

Note that this runs a new openssl command for each line of input, so this might not give the same results as the same input run through a single invocation of openssl.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.