Friday, May 3, 2024
42
rated 0 times [  42] [ 0]  / answers: 1 / hits: 59310  / 3 Years ago, sat, july 3, 2021, 1:22:37

How can I encode and decode percent-encoded (URL encoded) strings on the command line?



I'm looking for a solution that can do this:



$ percent-encode "ændrük"
%C3%A6ndr%C3%BCk
$ percent-decode "%C3%A6ndr%C3%BCk"
ændrük

More From » command-line

 Answers
0

These commands do what you want (using Python 2):


python -c "import urllib, sys; print urllib.quote(sys.argv[1])" æ
python -c "import urllib, sys; print urllib.unquote(sys.argv[1])" %C3%A6

If you want to encode spaces as +, replace urllib.quote with urllib.quote_plus.


I'm guessing you will want to alias them ;-)


[#44176] Saturday, July 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calcur

Total Points: 189
Total Questions: 80
Total Answers: 95

Location: Burkina Faso
Member since Thu, Dec 15, 2022
1 Year ago
;