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 stackexchange's answer:-
alias urldecode='python3 -c "import sys, urllib.parse as ul;print(ul.unquote_plus(sys.argv[1]))"'
Then you can use it as:-
urldecode '%22status%22%3A%22SUCCESS%22'
"status":"SUCCESS"
Now that's perfect. But the data that I want to decode must be passed through unix pipe, like this:-
grep 'status: 504' /var/log/local0* | awk '{ print $10}' | xargs urldecode
But this won't work, as xargs won't see the alias. So we alias xargs as well:-
alias xargs='xargs '
But that however only work for the first line. How to make xargs execute for each line?
alias xargs='xargs -L 1 '
Now we can run urldecode for each line we piped from grep!
Top comments (2)
We can also do it without
xargs
by usingsys.stdin
to read from pipee.g:
Thanks for the tips!