Computers and Technology
Computers and Technology, 19.07.2021 15:20, namdh6086

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".

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:00, 19elbatawisaly
What is one way in which tablets differ from laptops and notebooks? tablets are designed for touch-based interaction. tablets are designed to be used as desktops. tablets are designed for input via a keyboard and mouse. tablets are designed to be larger than laptops.
Answers: 1
image
Computers and Technology, 22.06.2019 12:10, drelisech6467
Linux is distributed under gnu gpl. why is this important? a. it ensures that only torvalds can profit from the sale of linux b. it prevents unknowledgeable users from downloading programs they don't know how to operate. c. it provides protection for the developers who created linux. d. it states that anyone can copy, modify, and share the program if changes are made public.
Answers: 1
image
Computers and Technology, 22.06.2019 14:00, GGerardi7552
What are procedures that keep a data base current
Answers: 1
image
Computers and Technology, 22.06.2019 20:40, broang23
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
Do you know the correct answer?
File Edit Format View Help grudgeons grudger gruellers gruesomest gruffily Grumbletonian grumbletoni...

Questions in other subjects:

Konu
Mathematics, 18.02.2021 18:00
Konu
Mathematics, 18.02.2021 18:00
Konu
Health, 18.02.2021 18:00