Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- error (){
- echo
- echo "This script will search for all the words written alternating the first set of characters with the second one, with the third set optionally in the middle. This is thought to be used for tilde characters. Acute character is activated with the right hand and then you press the letter with the left, hence it cannot be any of the other two sets."
- echo
- echo "Three arguments are needed. One for each set. Do just write all the chars together and separate each group with a space."
- echo "Spanish dictionary will be used by default. You can select a different one using the fourth argument to write the name as you find in /usr/share/dict/"
- echo "Writting -p as first argument, it will print the grep expression, but don't eval it"
- echo
- echo "Example: ./alterna qwertasdfgzxcvb yuiophjklnmñ áé"
- echo "Example: ./alterna qwertasdfgzxcvb yuiophjklnmç âáãéê portuguese"
- echo "Example: ./alterna -p aoeiupyqjkx fgcrldhtnsbmwvz áéíóú"
- echo
- exit
- }
- if [ "$1" = "-p" ]; then
- PRINT=1
- shift
- else
- PRINT=0
- fi
- if [ -z "$3" ]; then
- error
- fi
- if [ -z "$2" ]; then
- error
- fi
- if [ -z "$1" ]; then
- error
- fi
- #Filters those that alternate first group of letters with the second
- #Use the third parameter for accented letters (tilde with right hand and letter with left)
- GREP="grep -E '^(([$1][$3]?)|(([$1][$3]?[$2])+|([$1][$3]?([$2][$1][$3]?)+))"
- #and the second group with the first
- GREP="$GREP|(([$3]?[$2])|([$3]?[$2][$1])+|([$3]?[$2]([$1][$3]?[$2])+)))$'"
- #Here is where dictionaries are stored
- DICTURL=" /usr/share/dict/"
- #Changes the dictionary writting the name as the 4th argument
- if [ -z "$4" ]; then
- DICT=spanish
- else
- DICT=$4
- 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