K
K
kapitansen2020-10-20 17:02:58
bash
kapitansen, 2020-10-20 17:02:58

How to replace recursively urlencoded lines in files with normal ones using bash?

There is an archive of a static html site, some links in which are made like "lista-fundaci%C3%B3n". Folders and files, respectively, are called normally - lista-fundación. When you click on a link with special characters, the server returns 404. How to bring it into the proper form? I'm trying to write a command for autocorrect, but I'm not strong in bash.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lesha, 2020-10-20
@kapitansen

function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
for f in encoded.html enpage.html; do
    urldecode `cat "$f"` > "$f"
done

urldecode()

Z
zohan1993, 2020-10-20
@zohan1993

grep 'lista-fundaci%C3%B3n' -P -R -I -l * | xargs sed -i 's/lista-fundaci%C3%B3n/lista-fundación/g'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question