简体   繁体   中英

Insert/replace hash value: “Hexadecimal string contains non-hex character”

I was given a dump of a MySQL database and would like to load it into H2 in MySQL mode. It is working well so far except for the "users" table, which has hashed passwords in it and gives this error:

'Hexadecimal string contains non-hex character: "UQ�m������l�a_x"; 
SQL statement:INSERT INTO `users` VALUES (2,16,'him','UQ�m������l�a_x', ...);

Since they are not useful in this case, I could replace these hex strings with any other text value. Can I do that with sed, for instance?

I tried this: sed -e "s/'[\\d128-\\d255]'//g but it replaced 95% of my file.

I have seen answers preparing JDBC statements, but I have no hand on that (these are auto-applied "evolutions" of the Play framework).

To remove non-ascii text you can use tr or sed , here is one basic example using tr :

 echo -e "\xA9 "This is acsii text" \xA7 \xA3 \xA1 \xA2"
© This is acsii text § £ ¡ ¢

Not ascii chars removed : using tr -c -d '[[:alnum:]]|[[:space:]]|[:punct:]]'

echo -e "\xA9 "This is acsii text" \xA7 \xA3 \xA1 \xA2"   |tr -c -d '[[:alnum:]]|[[:space:]]|[[:punct:]]'
 This is acsii text 

OR

echo -e "\xA9 "This is acsii text" \xA7 \xA3 \xA1 \xA2"   |tr -cd '\000-\177'
 This is acsii text

使用另一个答案,我设法使其在sed中工作(增加了替换的可能性),如下所示:

sed -E -e "s/[^[:alnum:][:space:][:punct:]]//g"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM