The program grep (on Unix) or find (on Windows) is useful for writing out the lines in a file that match a specified text pattern.

computer science

Description

Q1) GREP FUNCTION 

The program grep (on Unix) or find (on Windows) is useful for writing out the lines in a file that match a specified text pattern. Write a script that takes a text pattern and collection of command-line arguments, grep.py pattern file1 file2 file3 and writes out the pattern in the listed files. The program should print the line number. As an example running something like:


That is, each line for which a match of pattern is obtained, is printed with a p


Hint 1): 

You can use sys.argv option for processing the input file list. 

Hint 2): 

Use grep function in Ubuntu to see the required format of the output. Your grep.py function should imitate grep “iter=” case*.res in the linux/unix terminal

 Hint 3) 

In your script there should be a main body of the program with two functions: grep and usage. 


Related Questions in computer science category