DEV Community

Python urldecode on command line

Kamal Mustafa on December 02, 2018

I have some logs that contain url with encoded characters and I need to extract some data out of the urls. Searching around lead me to this stackex...
Collapse
 
rrampage profile image
Raunak Ramakrishnan • Edited

We can also do it without xargs by using sys.stdin to read from pipe
e.g:

yes 'Mozilla%2F5.0%20%28Macintosh%3B%20U%3B%20Intel%20Mac%20OS%20X%2010.6%3B%20en' |\
 head -n 10 |\
 python3 -c "import sys, urllib.parse as ul; [print(ul.unquote_plus(l), end='') for l in sys.stdin]"
Collapse
 
k4ml profile image
Kamal Mustafa

Thanks for the tips!