
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Write a python
$Search tolkein1$ is the desired outlook(second image)

Transcribed Image Text:$ Search Ring Tolkien1
'Ring' found at:
line 1, column 7
line 6, column 5
line 6, column 32
line 7, column 5
$ Search 'nd t' Tolkien1
'nd t' found at:
line 6, column 42
line 7, column 50
$ Search ';' Tolkien2
';' found at:
line 2, column 26
line 8, column 5
$ Search Ring Tolkien2
'Ring' not found
$ Search Ring
Usage: Search <string> <file>
$ Search
Usage: Search <string> <file>
%24

Transcribed Image Text:In this project you will write yet another Python script to be run on the Unix timeshare, called Search.
This program will emulate the most elementary functionality of the grep command in Unix. The command
$ grep <string> <file>
where <string> is a string and <file> is a text file in your current working directory, prints all lines in
file <file> that contain the substring <string>. Depending on your terminal settings, it may also
highlight the occurrences of <string>in a different color. Download the files Tolkien1 and Tolkien2
from / Examples/lab5, and place them in a convenient directory on the timeshare (like ~/cse20/lab5).
From within that directory, type
$ grep Ring Tolkienl
and observe that all lines containing instances of the string 'Ring' are printed. Notice that there are 4
instances, and one instance is within the word "Rings". Thus, we see that grep is finding substrings of
each line, considered as a large string. You can also search for strings that contain spaces, as long as you
enclose that string in quotes (which you may do in any case.) Try doing
$ grep 'nd t' Tolkien1
to find two instances. Any string that contains characters having a special meaning to the bash interpreter,
such as the space, must be enclosed in quotes. For instance, if you search for a semi-colon ; by doing
$ grep ; Tolkien2
the interpreter thinks you are running two commands: grep (which gives you a usage message because you
gave it no arguments), followed by Tolkien2 (which gives a warning because the file is not executable).
On the other hand
$ grep ';' Tolkien2
sucsessfully locates two occurrences of ; within Tolkien2.
The command grep stands for: Globally search for a REgular expression and Print matching lines. A
regular expression, or regex, is a sequence of characters that specifies a search pattern. The simplest
possible such pattern is just a string to be searched for and matched, as demonstrated in the above examples.
More complex regular expressions can be used by grep to match sets of strings rather than just a single
string. We will not cover more advanced regular expressions here. Your Search program will emulate
the functionality of the grep on these elementary examples. Google the term regular expression to learn
more about this important concept, or do man grep to learn more about the functionality of the grep
command.
The output of Search will differ from that of grep in an essential way however. Instead of printing out
the lines with matching occurrences of <string>, Search will state the line number and column number
of (the beginning of) each occurrence of <string>within <file>. We illustrate the operation of Search
below on all of the preceding examples, and a few more.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- Python: Make hangman game with print() command to display output. Draw the hangman game using Matplotlib and show user how many guesses they have leftarrow_forwardin Python, create a simple program that asks the user for a list of items and save the list to a text file. Then, create a program to output the list.arrow_forwardWrite a python script that reads the file student.txt which contains the names of students. Print out "Loading the names of the students." Then print the various information found in the file. For testing write any 5 names in your file and attach your code, file, and output in the document.arrow_forward
- Write a program that creates the file "LetterGrades.txt" filled with 1000 randomly generated letter grades. Letter grades: A+, A, B+, B, C+, C, D+, D, and F. Python programarrow_forwardmake a example code related to orginizing files in python . Save it as 201916791. py and send screen shot with outputarrow_forwardExtract e-mails and passwords from several .txt files from a path to the folder to be searched and rewrite them in a symbolic .txt file : in Python code (do it in Visual Studio Code and run it)Example: hey... email: username+123@example.com, password: 627hsjwu* these are my company's credentials... See you later Now I want to put in a result.txt the email and the password separated by the symbol :arrow_forward
- The majority of source code is accessible in tarball format on the Internet. Is this statement true or false?arrow_forwardWrite a Python program in a .py file that includes the following: Using the menu.txt (see at the end) , prompt the user to either add or delete menu items, or update prices on existing menu items. Save the revised menu as a new text file. -------------------menu.txt-------------------Ham and Egg Sandwich $15.75Bacon and Cheese Plate $9.50Tuna Salad $12.30Beef Soup $9.00Spicy Beef Barbeque $20.00Pork Barbeque $18.00Oven Chicken Barbeque $15.00Pulled Beef Barbeque Burger $25.00House Salad $5.00Pellegrino $5.40White Wine $7.50Red Wine $11.00arrow_forwardIterating over a file like it's a list reads... O Everything in a file at once, into one string O Everything in a file at once, into a list One line from a file at a time O The number of characters in a file as an integerarrow_forward
- Using the list of names from the text files firstNames.txt open the file in Python. Iterate over the lines and create a regular expression that will print out the names that begin and end with the same letter. For instance the name “Anna” would be returned since it begins and ends with A. Submit on Omnivox when complete with exercise 1 firstname.txt aarenaarikaabagaelabagailabbeabbeyabbiabbieabbyabbyeabigaelabigailabigaleabraadaadahadalineadanadaraaddaaddiaddiaaddieaddyadeladelaadelaidaadelaideadeleadelheidadeliceadelinaadelindadelineadellaadelleadenaadeyadiadianaadinaadoraadoreadoreeadorneadreaadriaadriaensadrianadrianaadrianeadriannaadrianneadrienaadrienneaerielaerielaaeriellaftonagagaceagataagathaagatheaggiaggieaggyagnaagnellaagnesagneseagnesseagnetaagnolaagrethaaidaaidanaigneisailaaileaileeaileenailenearrow_forwardmake own code related to writing and reading files in python . Save file as mukhammadali.py and take a picturearrow_forwardWrite a python program that will open the file dataFile.csv, read its contents and print them out. Your output should look like this: First Last Age Wagejane Smith 21.00 21.50Jack Jones 20.00 19.50Edgar Martinez 22.00 22.75Zanab Sayegh 21.00 21.75arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY