英文:
having problem with converting in bash with Iconv
问题
iconv: illegal input sequence at position 0
如果我有一个用英语键盘布局写成的希伯来语字符串,我希望脚本返回相同的字符串,但使用希伯来语键盘布局。
我是一个新的bash用户,所以这可能是一个愚蠢的问题,但我真的找不到答案。
#!/bin/bash
read -p "Give me a word: " word
echo "$word" | iconv -t cp1255 | tr $(echo "[/קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ./קראטוןםפ}{שדגכעיחלך:\"|זסבהנמצ><?@#$^&~]" | iconv -t cp1255) "[qwertyuiop[]asdfghjkl;'\zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:\"|ZXCVBNM<><>?@#$^&~\`]"
echo "$word" | tr "[qwertyuiop[]asdfghjkl;'\zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:\"|ZXCVBNM<><>?@#$^&~\`]" $(echo "[/קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ./קראטוןםפ}{שדגכעיחלך:\"|זסבהנמצ><?@#$^&~]" | iconv -t cp1255) | iconv -t cp1255
英文:
iconv: illegal input sequence at position 0
If I have a string written in Hebrew language but in English keyboard layout, I want the script to return the same string but in Hebrew keyboard layout.
I'm a new bash user, so it might be a silly problem but I really can't find the answer.
#!/bin/bash
read -p "Give me a word: " word
echo "$word" | iconv -t cp1255 | tr $(echo "[/'\קראטוןםפ\]\[שדגכעיחלךף,\זסבהנמצתץ./'\קראטוןםפ}{שדגכעיחלך:\"|זסבהנמצ><?@#$^&~\]" | iconv -t cp1255) "[qwertyuiop\[\]asdfghjkl;'\\zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:\"|ZXCVBNM<>?@#$^&~\`]"
echo "$word" | tr "[qwertyuiop\[\]asdfghjkl;'\\zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:\"|ZXCVBNM<>?@#$^&~\`]" $(echo "[/'\קראטוןםפ\]\[שדגכעיחלךף,\זסבהנמצתץ./'\קראטוןםפ}{שדגכעיחלך:\"|זסבהנמצ><?@#$^&~\]"| iconv -t cp1255) | iconv -t cp1255
答案1
得分: 0
根据我理解你的问题,这只是一个字符映射,其中一个集合中的每个字符应该被第二个集合中的字符替换。tr
(不幸的是)不支持多字节字符或区域设置。
GNU sed 支持 Unicode。使用 y
命令,你可以在字符之间进行转换:
$ echo 'קראטו' | LC_ALL=C.UTF-8 sed 'y/קראטו/qwert/'
qwert
英文:
As I understand your question, there is just a simple map of characters, where every character from one set should be replaced by a character from the second set. tr
(sadly) does not support multi-byte characters nor locale.
GNU sed support Unicode. With y
command, you can translate between characters:
$ echo 'קראטו' | LC_ALL=C.UTF-8 sed 'y/קראטו/qwert/'
qwert
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论