hobkantau
hobkantau

Reputation: 13

How to decode an embedded base64 string?

I want to decode an embedded base64 string.

The base64 string itself is easily decoded with:

echo 'dGVsOis0OTEyMzQ1NjcK' | base64 -d

How can I decode an embedded base64 string?

Upvotes: 1

Views: 320

Answers (1)

Maxim Norin
Maxim Norin

Reputation: 1391

If you just want to receive the second line from the first line, then it should be like this:

MYSTRING="Subscriber,services,,1,dGVsOis0OTEyMzQ1NjcK"
RESULT="${MYSTRING%,*},$( base64 -d <<< ${MYSTRING##*,} )"
echo $RESULT
# Will print "Subscriber,services,,1,tel:+491234567"

If you need to do this for different records where encoded field is located in different positions, then it will be more complicated

Upvotes: 2

Related Questions