Advertisement
endermuabdib

alternacute.sh

Dec 17th, 2011
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. error (){
  4. echo
  5. 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."
  6. echo
  7. echo "Three arguments are needed. One for each set. Do just write all the chars together and separate each group with a space."
  8. 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/"
  9. echo "Writting -p as first argument, it will print the grep expression, but don't eval it"
  10. echo
  11. echo "Example: ./alterna qwertasdfgzxcvb yuiophjklnmñ áé"
  12. echo "Example: ./alterna qwertasdfgzxcvb yuiophjklnmç âáãéê portuguese"
  13. echo "Example: ./alterna -p aoeiupyqjkx fgcrldhtnsbmwvz áéíóú"
  14. echo
  15. exit
  16. }
  17.  
  18. if [ "$1" = "-p" ]; then
  19.  PRINT=1
  20.  shift
  21. else
  22.  PRINT=0
  23. fi
  24.  
  25. if [ -z "$3" ]; then
  26.  error
  27. fi
  28. if [ -z "$2" ]; then
  29.  error
  30. fi
  31. if [ -z "$1" ]; then
  32.  error
  33. fi
  34.  
  35. #Filters those that alternate first group of letters with the second
  36. #Use the third parameter for accented letters (tilde with right hand and letter with left)
  37. GREP="grep -E '^(([$1][$3]?)|(([$1][$3]?[$2])+|([$1][$3]?([$2][$1][$3]?)+))"
  38. #and the second group with the first
  39. GREP="$GREP|(([$3]?[$2])|([$3]?[$2][$1])+|([$3]?[$2]([$1][$3]?[$2])+)))$'"
  40.  
  41. #Here is where dictionaries are stored
  42. DICTURL=" /usr/share/dict/"
  43.  
  44. #Changes the dictionary writting the name as the 4th argument
  45. if [ -z "$4" ]; then
  46.  DICT=spanish
  47. else
  48.  DICT=$4
  49. fi
  50.  
  51. GREP="$GREP$DICTURL$DICT"
  52. if [ $PRINT = 1 ]; then
  53.  echo $GREP
  54. else
  55. eval $GREP
  56. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement