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

Procedure ·Open your UNTX environment and text editor. The previous lab describe

ID: 3911963 • Letter: P

Question

Procedure ·Open your UNTX environment and text editor. The previous lab described the Ubuntu t NTX shell tor windows 10 and the vi editor for text files. ·Open a tironal on UNIX Shell Scripting. o Go through chapters 1-7. As you read, try making your own similar shell text iles and runing en your UNIX eit, o In chapter 8, lea how to use the if-theu-else o In chapter 9, may learn how to use case statement ·Challenge to make and demonstrate. o Make a text file to be searched through using a shell script file you will make. An example might be a text file containing a person's favorite sports teams, such as Locaticn CreenBay Chicagc Team Color2 Creen Yellow Bears Black Orange o Have the file contain at least 10 lines. Topics could be sports, music, vacation places, movies, historical wars, types of snow, jewelry, etc. o Make a shell script file, and have the file do the following. Write itroduction so user knows the topic. Ask user to eter some attibute (oue word) of the ea, or wlhatever your lopic is. Have the code search through each lne of the file. Within that line, search through each word. See if the user requested word is there. ? f the word is ound, write a message saying what won word was ound and then printing the whole line om the file. Set a flag variable to a value that would indicate that at least one line contained that If the words no in a line, then do nothing At end of the search, give a sumary message to the user. If the word was never found in any linc, then write a messagc to indicatc that. Have so concluding message that indicates the search of the file is done. Demo Iunction to the instructor Snbmit on Bb Make a report with suitable header. Insert code for the shell text file. Insert the text of the sports teams (or whatever text data you used) that was scarched through. Submit on Bb ·Insert two examples of UNIX terminal running the shell script file, user interaction, and printed results.

Explanation / Answer

Bash Script :

#!/bin/bash

echo "This script searches the text file which contains data of the sports team."

echo "The data comprises of the location of the team , team name and the dress colors of the team."

echo "So the word to be searched must be relevant to the data in the text file."

#Path of the text file which is searched for the given word

file='/Users/kandy/Desktop/data.txt'

#Prompting the user to enter the input

echo 'Enter a word to be searched:'

#Reading the input

read answer

#An variable to keep track of how many times the given word is found in the file.

count=0

echo " "

#Iterating over the file

while IFS= read -r line

do

#If the given word exists in a line

if [[ $line =~ $answer ]]

then

echo "Given word was found in the below line"

echo $line

echo " "

#Incrementing the count variable

count=$((count + 1))

fi

done <"$file"

#Checking whether the given word is found at least once or not

if [ $count == 0 ]

then

echo "Given word doesn't exist in the file to be searched"

fi

#Exit message prompted onto the terminal

echo "The search for the given word in the text file is completed."

Sample Input and Output:

This script searches the text file which contains data of the sports team.
The data comprises of the location of the team , team name and the dress colors of the team.
So the word to be searched must be relevant to the data in the text file.
Enter a word to be searched:
Yellow


Given word was found in the below line
GreenBay Packers Green Yellow


Given word was found in the below line
Townsville North Queensland Cowboys Blue Yellow


Given word was found in the below line
Newcastle Hunter Mariners Blue Yellow


The search for the given word in the text file is completed.

Text file:

Location Team Color1 Color2
GreenBay Packers Green Yellow
Chicago Bears Black Orange
Sydney Glebe Dirty Reds White Brown
Newcastle Newcastle Rebels White Red
Auckland Auckland Warriors Grey Black
Townsville North Queensland Cowboys Blue Yellow
Gold Coast Gold Coast Titans Blue White
Sydney Northern Eagles Black White
Melbourne Melbourne Storm Purple White
Newcastle Hunter Mariners Blue Yellow

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote