C5 MS Word Template Accessible Secure Scripting The Basics lab: looking for Strings In this lab you will build a simple tool to look up words containing a sequence of characters (a string). You will...

i have fedora running on my VM and i am trying to do the attached class work but have no idea on how to complete in on my machine


C5 MS Word Template Accessible Secure Scripting The Basics lab: looking for Strings In this lab you will build a simple tool to look up words containing a sequence of characters (a string). You will build this script in three stages. First, assume that both the string and the filename are given. Next, assume that the string is to be read from the command line. Finally, create a script that will read both the string and the filename from the command line. Check for errors throughout the entire process. For this lab you will need the following files: · dict.txt · mycat.sh · x · y · x y Lab Exercise 1 Find the words in the word list “dict.txt” that contain the string “gry”. A. What is the format of the file “dict.txt”? How many words per line does it contain? B. Look up the program grep. What arguments would you give it to look for the string “gry” in dict.txt? C. Write a two-line shell script called “lookfor1.sh” that executes this command to look for words containing “gry” in dict.txt. The first line should specify that the program “#!/bin/bash” is to be used. The second line should contain your command. Try it out. If you did it right, you will see eight words, the first being “agrypnia” and the last being “pouggry”. Lab Exercise 2 Find the words in the word list “dict.txt” that contain a string supplied by the user. Hint: Begin with your script from Lab Exercise 1 and modify it as indicated. A. How do you represent the first argument from the command line in the command you put into your script? B. Modify the script you wrote for Lab Exercise 1 to take the string to be searched for from the command line. Test your script by searching for the strings “hello” and “world”. Call this script “lookfor2.sh”. C. What happens if no arguments are given? Two arguments? D. How would you embed a blank character in your argument? E. What happens if an argument contains a blank? F. Modify your script so that an argument with a blank is handled properly (that is, searched for in the file dict.txt). Call this script “lookfor2.sh”. Lab Exercise 3 Modify the script you wrote for Lab Exercise 2 by adding an “if” statement that checks whether there is exactly one argument. Call this script “lookfor3.sh”. If there is not exactly one argument, your script should print the error message “Usage: give exactly 1 argument, the string to be looked for” and exit immediately. Lab Exercise 4 Find the words in the word list named by the user (like “dict.txt”) that contain a string supplied by the user. Your shell script is to be called “lookfor4.sh”. Hint: Begin with your script from Lab Exercise 2 and modify it as indicated. A. Modify your script in Exercise 2 so that the word list is the second argument on the command line. Call this script “lookfor4.sh”. Remember to change your “if” statement so it balks if there are not exactly two arguments! B. Change the error message to “Usage: lookfor4 string file”. Call this script “lookfor4a.sh”. C. Change the error message so it prints the exact name of the script. That is, if you call the script “find4” and not “lookfor4.sh”, the error message should print as “Usage: find4 string file”. A similar error message should occur if you call the script “catdog” without changing the script! Call this script “lookfor4b.sh”. Puzzler In the script you wrote for Lab Exercise 4, if the file does not exist, grep prints an error message. This will be confusing to beginners. Add a test at the start of that script that prints the error message script_name: file file_name cannot be read where script_name is the name of the script and file_name is the name of the file that the user gives. Call this script “lookforp1.sh”. Big Puzzler This is for all you Linux experts. It demonstrates that there are several ways to write a script. A. Rewrite the script you wrote in Lab Exercise 4 using the program sed rather than grep. Call this script “lookforp2.sh”. B. Rewrite the script you wrote in Lab Exercise 4 using the program awk rather than grep. Call this script “lookforp3.sh”. What to submit For the parts of the exercises that do not require you to write a script, put your answers in a PDF or text file numbered appropriately, and call that file “Unit1answers.pdf” or “Unit1answers.txt” respectively. For the parts of the exercises that do require scripts, create plain text files to hold your script, and name the file containing your script as indicated in the problem instructions. Page | 1 This document is licensed with a Creative Commons Attribution 4.0 International License ©2017 Catalyzing Computing and Cybersecurity in Community Colleges (C5). Page | 3 This document is licensed with a Creative Commons Attribution 4.0 International License ©2017 Catalyzing Computing and Cybersecurity in Community Colleges (C5).
May 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here