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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |