I have a percent encoded file URL - for example file:///home/sashoalm/Has%20Spaces.txt
. I need to convert it to a local file - /home/sashoalm/Has Spaces.txt
.
How can I do that in bash?
In BASH you can use this utility function:
decodeURL() {
printf "$(sed 's#^file://##;s/+/ /g;s/%\(..\)/\\x\1/g;' <<< "$@")\n";
}
Then call this function as:
decodeURL 'file:///home/sashoalm/Has%20Spaces.txt'
/home/sashoalm/Has Spaces.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With