Advertisement
endermuabdib

alterna.sh

Dec 17th, 2011
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.73 KB | None | 0 0
  1. #!/bin/bash
  2. #Name of each dictionary
  3. SP="spanish"
  4. BR="british-english"
  5. AM="american-english"
  6. error (){
  7. echo
  8. echo "This script will search for all the words written alternating the first set of characters with the second one."
  9. echo
  10. echo "Two arguments needed. One for each set. Do just write all the chars together and separate each group with a space."
  11. echo "You can select the searching dictionary, use the third argument to  write the name as you find in /usr/share/dict/"
  12. echo "Shortnames for: -sp = spanish, -br=british-english, -am=american-english"
  13. echo "Example: ./alterna qwertasdfgzxcvb yuiophjklñnm br"
  14. echo "Example: ./alterna aoeiupyqjkx aoeiupyqjkx"
  15. echo "Writting -p as first argument will print the grep expression, but don't eval it"
  16. echo
  17. exit
  18. }
  19.  
  20. if [ "$1" = "-p" ]; then
  21.  PRINT=1
  22.  shift
  23. else
  24.  PRINT=0
  25. fi
  26.  
  27. if [ -z "$2" ]; then
  28.  error
  29. fi
  30. if [ -z "$1" ]; then
  31.  error
  32. fi
  33.  
  34. #Filters those words that start with the 2nd group and are followed by the 1st
  35. #and finally are optionally followed by the 2nd again (so we get even and odd words). And the same starting on the first group.
  36. GREP="grep -E '^((([$2][$1])+[$2]?)|(([$1][$2])+[$1]?))$'"
  37.  
  38. #Here is where all the dictionaries are stored
  39. DICTURL=" /usr/share/dict/"
  40. #Spanish dictionarie selected by default
  41. DICT=$SP
  42.  
  43. #Also is possible to search within the british and american dictionaries
  44. #choosing them in the third argument by writting 'br' or 'am'
  45. if [ -z "$3" ]; then
  46.  DICT=$SP
  47. else
  48.  if [ "$3" = "-br" ]; then
  49.   DICT=$BR
  50.  else
  51.   if [ "$3" = "-am" ]; then
  52.    DICT=$AM
  53.   else
  54.    if [ "$3" = "-sp" ]; then
  55.     DICT=$SP
  56.    else
  57.     DICT=$3
  58.    fi
  59.   fi
  60.  fi
  61. fi
  62.  
  63. GREP="$GREP$DICTURL$DICT"
  64. if [ $PRINT = 1 ]; then
  65.  echo $GREP
  66. else
  67. eval $GREP
  68. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement