Skip to content

Instantly share code, notes, and snippets.

@tomsmeding
Created April 12, 2015 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomsmeding/0347fb560dd34fd998c2 to your computer and use it in GitHub Desktop.
Save tomsmeding/0347fb560dd34fd998c2 to your computer and use it in GitHub Desktop.
Vertalen op de commandline
#!/usr/bin/env bash
if [[ "$#" != "3" ]]; then
echo "Give on the command line: from-language to-language word"
echo "Languages: NL EN DE FR ES"
exit
fi
text=$(w3m "http://www.mijnwoordenboek.nl/vertaal/$1/$2/$3" | cat)
startline=$(echo "$text" | grep -ne '^Vertalingen' | sed 's/:.*//')
text=$(echo "$text" | gtail -n "+$startline")
endline=$(echo "$text" | grep -ne '^Staat je antwoord er niet bij\|^Zojuist vertaald\|^Voorbeeldzinnen met' | ghead -n +1 | sed 's/:.*//')
endline=$(($endline - 1))
echo "$text" | ghead -n "+$endline" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'
@tomsmeding
Copy link
Author

Dependency: w3m. Uses gtail and ghead because it requires the GNU version of the commands, not the BSD version that osx provides. On a GNU system, you can just use tail and head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment