Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a Bash script that includes getopts, AWK and SAD programs. Name your script according to our convention (e.g., As_5_YourName.sh). As you know, you may

write a Bash script that includes getopts, AWK and SAD programs. Name your script according to our convention (e.g., As_5_YourName.sh). As you know, you may have to compress it using ZIP software in order to submit it via Blackboard. Make sure to comment and indent your code. Also, make sure to use #! line and add some explanations when you print/output something to a screen/terminal

Your script should:

1. Process options and an argument passed to it.

a. Process an argument passed to it as a positional parameter (note that one of the options will require its own arguments, as explained latter). You may assume that there will be only one argument passed to your script i. The argument to your script should represent an already existing file in the working directory. The file pointed by the argument will be processed later in your script by AWK and SED programs ii. Check if the user passed to your script a valid argument and if it refers to a valid file name in the working directory ? If not, print/display error and usage messages and exit the script ? If yes, print/display a message confirming receiving a valid argument

b. Process three options -d, -s, and -a (use getopts command to do it)

You may assume that option -a is the last option used by the user in the string of options that he/she wants your script to process

i. If option -d is used ? Check if directory Assignment_5 exists in the working directory ? Print/display confirmation message if it is there o If not, create it (Assignment_5 directory) in a working/current directory and reassure that you successfully created it ? Print/display error and usage messages if it could not be created ? Print/display appropriate message if you successfully created it or it already existed (note two different messages for two different situations) ? You will use this directory later to store/save outputs of your script

ii. Option -s should trigger a SED program within your script that ? Checks if a file salary.rec exists in a working directory ? Prints appropriate messages depending if the file salary.rec is or is not there ? If the file slary.rec does not exist in the working directory, exit the script ? You can assume that the file salary.rec has the same format as the file example_salary_data_file that I distributed via Blackboard ? Delete all the lines within the file that start with capital letter A, B, or C ? Saves the changes made by SED as a file within the directory that you checked/created in 1.a, Name the file with your name and extension .sed_output

iii. Option -a expects its own argument (not the argument to your script, that also has to be passed to it as explained in 1.a) ? Option -a argument should be a single letter character o Check for a validity of the argument to option -a and print appropriate messages as needed. If no argument to option -a is send, print/display appropriate message and exit your script ? When option -a is invoked with a valid argument to it, run AWK o Use an argument to your script (see 1.a) as the input to AWK o Print/output your name at the beginning of an output of AWK o Print/output all records for which the first letter of first field starts with the argument to option -a o Print/output number of records for which the first letter of first field starts with argument to option -a o Save output of AWK as a file within the directory which you checked/created in 1.a, Name the file with your name and extension .awk_output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

(3) Who is performing well and who is not performing well?

Answered: 1 week ago