subject

File Edit Format View Help grudgeons grudger gruellers gruesomest gruffily Grumbletonian grumbletonian grummels grummeter grumpishness grunerite gruneritization Grunth gruppetto grutten gruyere grylle Gryllotalpa Grynaeus grypanian gryph Gryphosaurus gryposis G-shaped gt. gte g. u. guachamaca Guadalupita Guaharibo guaka guan Guanche guanidin guanidopropionic guanize mycat - Notepad File Edit Format View Help ##!/bin/sh cat $1 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".
What is the format of the file "dict. txt"? How many words per line does it contain? 7 Text file
Look up the program grep. What arguments would you give it to look for the string "gry" in dict. txt?
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/sh" 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.
How do you represent the first argument from the command line in the command you put into your script?
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".
What happens if no arguments are given? Two arguments?
How would you embed a blank character in your argument?
What happens if an argument contains a blank?
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.
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!
Change the error message to "Usage: lookfor4 string file". Call this script "lookfor4a. sh".
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.
Rewrite the script you wrote in Lab Exercise 4 using the program sed rather than grep. Call this script "lookforp2.sh".
Rewrite the script you wrote in Lab Exercise 4 using the program awk rather than grep. Call this script "lookforp3.sh".

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 10:20
Write a program that keeps asking the user for new values to be added to a list until the user enters 'exit' ('exit' should not be added to the list). these values entered by the user are added to a list we call 'initial_list'. then write a function that takes this initial_list as input and returns another list with 3 copies of every value in the initial_list. finally, inside print out all of the values in the new list. for example: input: enter value to be added to list: a enter value to be added to list: b enter value to be added to list: c enter value to be added to list: exit output: a b c a b c a b c note how 'exit' is not added to the list. also, your program needs to be able to handle any variation of 'exit' such as 'exit', 'exit' etc. and treat them all as 'exit'.
Answers: 2
question
Computers and Technology, 24.06.2019 22:00
Aobject is used for displaying the results of a question based on stored data. a. query b. report c. table d. form
Answers: 2
question
Computers and Technology, 25.06.2019 05:10
Write a program that asks for 'name' from the user and then asks for a number and stores the two in a dictionary (called 'the_dict') as key-value pair. the program then asks if the user wants to enter more data (more data (y/n)? ) and depending on user choice, either asks for another name-number pair or exits and stores the dictionary key, values in a list of tuples and prints the list. note: ignore the case where the name is already in the dictionary. example: name: pranshu number: 517-244-2426 more data (y/n)? y name: rich number: 517-842-5425 more data (y/n)? y name: alireza number: 517-432-5224 more data (y/n)? n [('alireza', '517-432-5224'), ('pranshu', '517-244-2426'), ('rich', '517-842-5425')]
Answers: 3
question
Computers and Technology, 25.06.2019 06:50
The federal sentencing guidelines for organizations set the tone for organizational ethics compliance programs by question 1 options: a) codifying into law incentives for organizations to take action such as developing ethical compliance programs to prevent misconduct. b) forcing all organizations to develop mandatory reporting systems and ethics programs. c) eliminating most of the federal legislation that created inefficient and time-consuming activities for businesses. d) providing detailed guidelines for how to set up organizational ethics programs to guard against unethical conduct. e) providing a thorough examination of company codes of ethics to determine whether they are sufficient.
Answers: 1
You know the right answer?
File Edit Format View Help grudgeons grudger gruellers gruesomest gruffily Grumbletonian grumbletoni...
Questions
question
Mathematics, 06.02.2020 01:47
question
Mathematics, 06.02.2020 01:47
Questions on the website: 13722361