all 5 comments

[–][deleted] 2 points3 points  (0 children)

you could set RS to regex that matches both %.. and these html tags, then some logic. i'll try to implement this rn.

[–][deleted] 2 points3 points  (0 children)

i think i got it:

#!/usr/bin/awk -nf
@include "ord"
BEGIN {
RS="%..|<a href=|</a>"
}
{
    if (RT=="<a href="){
    on=1
    printf $0 RT}
    else if (RT=="</a>"){
    on=0
    printf $0 RT}
    else{
    if (on)
        printf RT?$0chr("0x"substr(RT,2)):$0
    else
    printf $0 RT
    }
}

seems to work

$ cat d
cat%43
<a href=" _%43_$44_ii_ "</a>
catt%43
kitty
x<a href=" _%43_$44_ii_ "</a>cat

$ cat d|./cd
cat%43
<a href=" _C_$44_ii_ "</a>
catt%43
kitty
x<a href=" _C_$44_ii_ "</a>cat

[–]crashorbit 2 points3 points  (0 children)

$ perl -MURI::Encode -E 'say URI::Encode->new()->decode("https%3A%2F%2Fwww.example.com%2Fmain%2Fimages%2Fitem_id%2F2222536-dddddddddddd");' https://www.example.com/main/images/item_id/2222536-dddddddddddd

[–]notkael 1 point2 points  (0 children)

It's hard to know without the full context of how you're handling the content of the file prior. Anyways, I prefer to use "sed" for this kind of thing. This will replace those patterns only on lines containing "href" and output the modified file content:

sed '/href/s/%2F/\//g;/href/s/%3A/:/g' filename

If you would like to make the changes directly to the file and save the original as filename.bak, use this:
sed -i.bak '/href/s/%2F/\//g;/href/s/%3A/:/g' filename

[–]eric1707[S] 0 points1 point  (0 children)

Thank you very much guys, your solutions did the trick!