Convert percent-encoded file URL to local file in bash
bash, url
Solution
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
Problem
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?