1

I have a file which contains long lines made of text mixed with encoded character.

%255D%252C%2522actualPage%2522%253A1%252C%2522rowPerPage%2522%253A50%257D%255D

Each encoder character is %25xx where xx is the hexa value of the ascii char (ex. %2540 = @)

I tried the folowing but w/o success

perl -pe 's/%25([0-9A-F](0-9A-F])/\x$1/' myfile.txt
perl -pe 's/%25([0-9A-F](0-9A-F])/chr($1)/' myfile.txt

Do you have any clue for me ?

TIA, Peyre

TLP
  • 66,756
  • 10
  • 92
  • 149
Peyre
  • 397
  • 2
  • 14

3 Answers3

3

Perhaps what you want is URI::Encode. It is a better idea to use a module for this than a regex.

perl -MURI::Encode -nle'$u=URI::Encode->new(); print $u->decode($u->decode($_));'

Output is this for your input string:

],"actualPage":1,"rowPerPage":50}]

As you'll notice, the string had to be decoded twice, because it had been encoded twice (%25 is apparently the percent sign %). The interim output was

%5D%2C%22actualPage%22%3A1%2C%22rowPerPage%22%3A50%7D%5D
TLP
  • 66,756
  • 10
  • 92
  • 149
2
perl -MURI::Escape -ne'print uri_unescape(uri_unescape($_))'
ikegami
  • 367,544
  • 15
  • 269
  • 518
0
perl -pe 's/%25([0-9A-F][0-9A-F])/chr hex $1/ge' myfile.txt

output

],"actualPage":1,"rowPerPage":50}]
mpapec
  • 50,217
  • 8
  • 67
  • 127