Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quoted Printable encode/decode bash aliases - suitable for pipelining
# To decode:
# qp -d string
# To encode:
# qp string
alias qpd='perl -MMIME::QuotedPrint -pe '\''$_=MIME::QuotedPrint::decode($_);'\'''
alias qpe='perl -MMIME::QuotedPrint -pe '\''$_=MIME::QuotedPrint::encode($_);'\'''
function qp {
if [[ "$1" = "-d" ]]
then
echo ${@:2} | qpd
else
echo ${@} | qpe
fi
}
@klepsydra

This comment has been minimized.

Copy link

klepsydra commented May 1, 2012

Don't forget to "shopt -s expand_aliases" if you plan to use these aliases in bash scripts

@jjarmoc

This comment has been minimized.

Copy link
Owner Author

jjarmoc commented May 1, 2012

Good call, thanks! I tend to use them mostly in one liners so I can pipeline to other tools easily, but that's a good point worth noting.

@Hubro

This comment has been minimized.

Copy link

Hubro commented Apr 27, 2018

Alternatively, use Python's quopri module:

$ echo "Jeg liker å sykle" | python -m quopri
Jeg liker =C3=A5 sykle

$ echo "Jeg liker =C3=A5 sykle" | python -m quopri -d
Jeg liker å sykle
@AloisMahdal

This comment has been minimized.

Copy link

AloisMahdal commented Mar 4, 2019

@Hubro: this should be the accepted answer!

(oh wait, I'm not on stackoverflow?)

@eiro

This comment has been minimized.

Copy link

eiro commented Apr 26, 2019

the perl version can be much simple:

qp () {
    perl -MMIME::QuotedPrint -s -ne '
        BEGIN { *e = $d ? \&decode_qp : \&encode_qp }
        print e $_
    ' -- "$@"
}

qp /etc/hostname - /etc/hostname <<< ∀✓ | qp -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.