Return to Snippet

Revision: 16612
at August 15, 2009 15:39 by deepsoul


Updated Code
#!/bin/sh

onetwo='.{1,2}'
re="$1"
re="${re//[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/.}"
re="${re//ue/$onetwo}"
re="${re//ae/$onetwo}"
re="${re//oe/$onetwo}"
re="${re//ss/$onetwo}"

# have to use perl for grepping because of umlauts

lynx -dump -nolist 'http://dict.leo.org/ende?lp=ende&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=on&spellToler=on&search='"$1"'&relink=on' | perl -n -e "print if /$re/i;"

Revision: 16611
at August 9, 2009 11:27 by deepsoul


Initial Code
#!/bin/sh

onetwo='.{1,2}'
re="$1"
re="${re//[^abcdefghijklmnopqrxyzABCDEFGHIJKLMNOPQRXYZ]/.}"
re="${re//ue/$onetwo}"
re="${re//ae/$onetwo}"
re="${re//oe/$onetwo}"
re="${re//ss/$onetwo}"

# have to use perl for grepping because of umlauts

lynx -dump -nolist 'http://dict.leo.org/ende?lp=ende&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=on&spellToler=on&search='"$1"'&relink=on' | perl -n -e "print if /$re/i;"

Initial URL

                                

Initial Description
The script below looks up its first argument on the LEO German-English dictionary.  It is really just a dump of the rendered result page by `lynx` followed by a grep.  But grep cannot handle the possible umlauts in the result page, so Perl is used for that.  The first paragraph constructs a regular expression which replaces umlauts and their two-character aliases with partial regexes matching anything.  The regex fraction `$onetwo` also matches two arbitrary characters, so it still works if the two-char sequence did not denote an umlaut.

Initial Title
Query LEO dictionary from shell

Initial Tags

                                

Initial Language
Bash