In the Linux shell environment, there is an OD command that allows files to be exported in different ASCII code, which completes the task of converting Chinese characters to URL encoding under the Linux shell.
The URL encoding is a hexadecimal-like%e6%9c%8d%e5%8a%a1%e5 string, and test is a file that contains the characters "database network," The following command output:
#od -t x /test
0000000 ddbefdca f8cde2bf 0a2ce7c2
0000014
The string corresponds to the URL encoding%ca%fd%be%dd%bf%e2%cd%f8%c2%e7%2c.
You can see the corresponding relationship between the encodings. The following is the script for the conversion:
CODE:#!/bin/sh
#make url code
od -t x /test |awk '{
w=split($0,linedata," ");
for (j=2;j<w+1;j++)
{
for (i=7;i>0;i=i-2)
{
if (substr(linedata[j],i,2) != "00") {printf "%" ;printf toupper(substr(linedata[j],i,2));}
}
}
}' >/testurl
The content of the Testurl file is the result of the conversion.