Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 3 Using the script “menu” as a template, complete the application with t

ID: 3607509 • Letter: P

Question

Project 3

Using the script “menu” as a template, complete the application with the following options:

print today’s date

print a list of male names

provide option to sort by name

provide option to print only the first “n” number

print a list of female names

provide option to sort by name

provide option to sort by name in reverse

print a list that combines both boy and girl names

provide option to save results to file

provide option to sort by name

provide option to print only names occurring less than “n” times

provide exit mechanism that sets error code to zero. Otherwise error code should be set to 10

Each option will clear the screen, query for any options, print results, and wait for the user to
“Hit any key...”

This is for a UNIX class, using terminal on Mac.

Script "menu" below:

choice=""

until [ "$choice" = "q" ]

do

   clear

   tput cup 5 20

       printf "item 1 "

   tput cup 6 20

       printf "item 2 "

   tput cup 7 20

       printf "item 3 "

   tput cup 8 20

       printf "item 4 "

   tput cup 9 20

       printf "Quit q "

   tput cup 11 30

   read choice

  

   case $choice in

       "1")

           echo "List Male Names Only"

           ;;

       "2")

           echo "List Female Names Only""

           ;;

       "3")  

           echo "item 3"

           ;;

       "4")

           echo "item 4"

           ;;

      

       "q")

           echo "quitting"

           ;;

       *)

           echo "Not an option!"

   esac

done  

Explanation / Answer

Script "menu" below:
date '+DATE: %m/%d/%y%n'
choice=""

until [ "$choice" = "q" ]

do

    clear

    tput cup 5 20

        printf "List Male Names Only "

    tput cup 6 20

        printf "List Female Names Only "

    tput cup 7 20

        printf "list that combines both boy and girl names "

    tput cup 8 20

        printf "item 4 "

    tput cup 9 20

        printf "Quit q "

    tput cup 11 30

    read choice  

    case $choice in

        "1")

            echo "List Male Names Only. Enter the option: a) sort by name b) print only the first n number"
           read opt
           if [ $opt == 'a' ] then sort filename
           else echo enter value of n
                   read nn
                   head filename -$nn
           fi

            ;;

        "2")

            echo "List Female Names Only. Enter the option: a) sort by name b) sort by name in reverse"
           read opt
           if [ $opt == 'a' ] then sort filename asc
           else sort filename desc
           fi
            ;;

        "3")  

            echo "list that combines both boy and girl names. Enter the option: a) save results to file b) sort by name c) print only names occurring less than “n” times."
           read opt
           if [ $opt == 'a' ] then echo 'saving results to file, enter file name to save'
                                   read fileName1
                                   cat file1, file2 > fileName1
           elseif [ $opt == 'b' ] sort file1, file2
           else    echo 'enter value of n'
                   read n
                   awk '{a[$0]++}END{for(i in a){if(a[i] > $n){print i}}}' a.txt
           fi
            ;;

        "4")

            echo "item 4"

            ;;

      

        "q")

            echo "quitting"

            ;;

        *)

            echo "Not an option!"

    esac

done