Shell Script-translating English words

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.