Advertisement
solidsnake

OS Address Book Exercise (No functions)

Jan 27th, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Author - MR
  2. #Date modified - 1/28/14
  3.  
  4. echo "Rosales,Clifford,123456,crosales@guidon.com" > addressbook
  5. echo "Hizon,Joseph,654321,jhizon@batak.com" >> addressbook
  6. echo "Raymundo,Miguel,789012,mraymundo@gmail.com" >>addressbook
  7.  
  8. until [ "$choice" == "4" ] #watch out for rookie mistakes
  9.     do
  10.         echo "======================"
  11.         echo "What do you want to do?"
  12.         echo "======================"
  13.         echo "1. Add new record"
  14.         echo "2. Display all records"
  15.         echo "3. Search"
  16.         echo "4. Exit"
  17.         echo "======================"
  18.         echo -n "Choice: "
  19.         read choice
  20.         echo
  21.        
  22.         if [ "$choice" == "1" ] #string -> "$x" == "y" --- int -> $x -eq y
  23.         then
  24.             echo -n "Enter last name: "
  25.             read last
  26.             echo -n "Enter first name: "
  27.             read first
  28.             echo -n "Enter contact number: "
  29.             read number
  30.             echo -n "Enter email address: "
  31.             read email
  32.             echo "$last,$first,$number,$email" | sed 's/,/ ~~~ /g' >> addressbook
  33.             echo
  34.             echo "~~~RECORD SUCCESSFULLY ADDED~~~"
  35.             echo
  36.  
  37.         elif [ "$choice" == "2" ]
  38.         then
  39.             cat addressbook | sed 's/,/ /g' | awk '{printf "%-15s%-15s%-15s%-15s\n",$1,$2,$3,$4}'
  40.             echo
  41.  
  42.         elif [ "$choice" == "3" ]
  43.         then
  44.             echo -n "Entery query: "
  45.             read query
  46.             echo
  47.             echo "SEARCH RESULTS:"
  48.             echo
  49.             cat addressbook | grep -i $query
  50.             echo
  51.  
  52.         else
  53.             echo β€œINVALID CHOICE”
  54.             echo
  55.         fi
  56.     done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement