Script: phonedecode

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

script: phonedecode

This script should take a phone number from the command line and translate it into just numbers. For example, if it is invoked as phonedecode 1-800-eat-meat, it should print 1-800-328-6328. The translation shoult follow what is found on a touch-tone phone.

  1. The attempts at a solution (include all code and scripts):

This takes a file as an argument: phonedecode testphonedecode.txt
(where testphonedecode.txt contains: 1-800-eat-meat) and phonedecode contains:

(sed 's/[a-c]/2/g' | sed 's/[d-f]/3/g' | sed 's/[g-i]/4/g' |
 sed 's/[j-l]/5/g' | sed 's/[m-o]/6/g' | sed 's/[p-s]/7/g' |
 sed 's/[t-v]/8/g' | sed 's/[w-z]/9/g') < $1

But I would like to be able to write: phonedecode 1-800-eat-meat
how can I go about passing the telephone number as the argument?

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Villanova, PA, Nadi, 8700, CSC 8700

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Put following code in file called phonedecode. Make it executable (chmod 755 phonedecode)

#!/bin/bash

echo "$1" | sed 's/[a-c]/2/g' | sed 's/[d-f]/3/g' | sed 's/[g-i]/4/g' |
sed 's/[j-l]/5/g' | sed 's/[m-o]/6/g' | sed 's/[p-s]/7/g' |
sed 's/[t-v]/8/g' | sed 's/[w-z]/9/g'