I've been learning Linux and shell scripts lately. English has not been returned to teachers for many years. Encountered the words do not understand to open a Word bully Web dictionary to translate, a long time more uncomfortable. Accidentally found http://www.iteye.com/topic/819440 mentioned a translation of the English word shell script, unfortunately, many years ago, and is now used by the wall of Google, of course, the failure.
Translate () {wget-qo-"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$ {2:-en}|${3:-zh} "| SED-E-n ' s/[[:alnum:] ": {}]+" Translatedtext ":" ([^ "]+)". */\1/p '; return 0; }
In order to facilitate their own learning and practiced hand, modify the Cheng Jinshan dictionary. Suffering from the level of half a barrel of water, repeatedly used a number of pipelines and SED filtering and typesetting, and finally reluctantly available. Write to communicate, let each road master to the younger brother correction:
Translate () {echo echo "${1}:" wget-qo-"http://www.iciba.com/$1" | Sed-n '/"Prons"/,/"net_paraphrase"/P ' | Sed-e ' s/<[^>]*>//g '-e ' s/[[:space:]]//g ' | Tr-d ' \ n ' | Sed-e ' s/]/]\t/'-e ' s/[a-z]*\./\n&/g ' echo echo return 0; }
Put this function in the ~/.BASHRC, re-open a terminal can be used:
$ translate computercomputer: British [Kmpju:t (R)] Beauty [kmpjut]n. (electronic) computer, computer $
This place itself has been not very satisfied, feel there is always a more concise way to achieve:
Sed-n '/"Prons"/,/"net_paraphrase"////positioning required code block, I choose from pronunciation to simple meaning part sed-e ' s/<[^>]*>//g '-e ' s/[[:space:]]//g ' Delete all <...> HTML tags and spaces tr-d ' \ n '//delete all line breaks and line up the text sed-e ' s/]/]\t/'-e ' s/[a-z ]*\./\n&/g '//Phonetic Alphabet plus tab, Word of speech before adding line
This article is from the "Willron Study notes" blog, so be sure to keep this source http://willron.blog.51cto.com/4871077/1574834
Shell Script-translating English words