Reputation: 13
I want to decode an embedded base64 string.
input line:
Subscriber,services,,1,dGVsOis0OTEyMzQ1NjcK
expected output:
Subscriber,services,,1,tel:+491234567
The base64 string itself is easily decoded with:
echo 'dGVsOis0OTEyMzQ1NjcK' | base64 -d
How can I decode an embedded base64 string?
Upvotes: 1
Views: 320
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