Guest User

numbers to words

a guest
Jan 17th, 2017
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ cat n2w
  2. #! /bin/bash
  3.  
  4. [ $# -eq 1 ] && expr "$1" : '^[0-9]*$' >/dev/null 2>&1 || {
  5.   echo 1>&2 "Command format is \"$(basename $0) n\"."
  6.   exit 1
  7.   }
  8.  
  9. #     0  1  2   3   4   5   6   7    8   9
  10. d2l=( '' '' abc def ghi jkl mno pqrs tuv wxyz )
  11.  
  12. n=$1
  13. p=''
  14. while (( n > 0 )) ; do
  15.   (( d = n % 10 ))
  16.   (( n = n/10 ))
  17.   if (( d > 1 )) ; then
  18.     p="[${d2l[$d]}]$p"
  19.   fi
  20. done
  21.  
  22. grep -i "^$p\$" /usr/share/dict/american-english
  23.  
  24. $ ./n2w 228
  25. act
  26. bat
  27. cat
  28.  
  29. $ ./n2w 96737
  30. words
  31.  
  32. $ ./n2w 6862377
  33. Numbers
  34. numbers
  35.  
  36. $ ./n2w 2244744
  37.  
  38. $ ./n2w 4744
  39.  
  40. $ ./n2w 2243224
  41.  
  42. $ ./n2w 3224
  43. each
  44.  
  45. $
RAW Paste Data