Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Name of each dictionary
- SP="spanish"
- BR="british-english"
- AM="american-english"
- error (){
- echo
- echo "This script will search for all the words written alternating the first set of characters with the second one."
- echo
- echo "Two arguments needed. One for each set. Do just write all the chars together and separate each group with a space."
- echo "You can select the searching dictionary, use the third argument to write the name as you find in /usr/share/dict/"
- echo "Shortnames for: -sp = spanish, -br=british-english, -am=american-english"
- echo "Example: ./alterna qwertasdfgzxcvb yuiophjklñnm br"
- echo "Example: ./alterna aoeiupyqjkx aoeiupyqjkx"
- echo "Writting -p as first argument will print the grep expression, but don't eval it"
- echo
- exit
- }
- if [ "$1" = "-p" ]; then
- PRINT=1
- shift
- else
- PRINT=0
- fi
- if [ -z "$2" ]; then
- error
- fi
- if [ -z "$1" ]; then
- error
- fi
- #Filters those words that start with the 2nd group and are followed by the 1st
- #and finally are optionally followed by the 2nd again (so we get even and odd words). And the same starting on the first group.
- GREP="grep -E '^((([$2][$1])+[$2]?)|(([$1][$2])+[$1]?))$'"
- #Here is where all the dictionaries are stored
- DICTURL=" /usr/share/dict/"
- #Spanish dictionarie selected by default
- DICT=$SP
- #Also is possible to search within the british and american dictionaries
- #choosing them in the third argument by writting 'br' or 'am'
- if [ -z "$3" ]; then
- DICT=$SP
- else
- if [ "$3" = "-br" ]; then
- DICT=$BR
- else
- if [ "$3" = "-am" ]; then
- DICT=$AM
- else
- if [ "$3" = "-sp" ]; then
- DICT=$SP
- else
- DICT=$3
- fi
- fi
- fi
- fi
- GREP="$GREP$DICTURL$DICT"
- if [ $PRINT = 1 ]; then
- echo $GREP
- else
- eval $GREP
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement