Due: Thu, Sept 12 @7:00am
Suppress normal output; instead print a count of matching lines for the input file. With the -v option, count non-matching lines.
Print a usage statement to stdout and exit with status 0.
Prefix each line of output with the 1-based line number of the file, followed immediately by a colon (e.g., 1:foo).
Quiet; do not write anything to stdout. Exit immediately with zero status if any match was found. If a match is not found, exit with a non-zero status.
Print NUM lines of leading context before matching lines.
Implement the following feature:
Perform a case-insenstive match for STR.
Remember to include a blank file called bonus1 in your project submission so that I know to grade this feature.
Implement the following feature:
Invert the sense of matching, to print non-matching lines.
Remember to include a blank file called bonus2 in your project submission so that I know to grade this feature.
Submit your project as a zip file via gradescope. Your project must include a Makefile that builds an executable called sgrep. Please refer to the instructions for submitting an assignment for details on how to login to gradescope and properly zip your project.
Input Files: alice.txt dorothy.txt
Helper Source Files: You can download a zip file with the starter code (sgrep.c, mu.c, mu.h, list.h, Makefile).
./sgrep apple
Prints a a one line messge to stderr.
./sgrep apple nonexistent.txt
Prints a message to stderr that includes the text No such file (case-insenstive).
./sgrep apple nonexistent.txt
Exits with a nonzero status.
./sgrep -h
Prints a usage statement to stdout. The statement should start with either Usage or usage. You can decide the rest of the content. Conventionally, this option either prints the synopsis or a more verbose statement that also includes a description of the options.
./sgrep -h
Exits with a status of 0.
./sgrep -c pie alice.txt
(out) 0
Has the above output (stdout).
./sgrep -c pie alice.txt
Exits with nonzero status.
./sgrep -c cake alice.txt
(out) 3
Has the above output (stdout).
./sgrep -c cake alice.txt
Exits with status of 0.
./sgrep -q rainbox alice.txt
Prints nothing.
./sgrep -q rainbox alice.txt
Exits with nonzero status.
./sgrep -q golden alice.txt
Prints nothing.
./sgrep -q golden alice.txt
Exits with status of 0.
./sgrep -n key alice.txt
(out) 107:glass; there was nothing on it except a tiny golden key, and Alice's
(out) 109:but, alas! either the locks were too large, or the key was too small,
(out) 113:little golden key in the lock, and to her great delight it fitted!
(out) 128:back to the table, half hoping she might find another key on it, or at
(out) 149:flavour of cherry-tart, custard, pine-apple, roast turkey, toffee, and
(out) 167:door, she found she had forgotten the little golden key, and when she
(out) 188:Alice, "and if it makes me grow larger, I can reach the key; and if it
Has the above output (stdout).
./sgrep -B1 garden alice.txt
(out) much larger than a rat-hole: she knelt down and looked along the
(out) passage into the loveliest garden you ever saw. How she longed to get
(out) brightened up at the thought that she was now the right size for going
(out) through the little door into that lovely garden. First, however, she
(out) After a while, finding that nothing more happened, she decided on going
(out) into the garden at once; but, alas for poor Alice! when she got to the
(out) makes me grow smaller, I can creep under the door; so either way I'll
(out) get into the garden, and I don't care which happens!"
Has the above output (stdout).
./sgrep -B3 cupboards alice.txt
(out) was going to happen next. First, she tried to look down and make out
(out) what she was coming to, but it was too dark to see anything; then she
(out) looked at the sides of the well, and noticed that they were filled with
(out) cupboards and book-shelves; here and there she saw maps and pictures
(out) passed; it was labelled "ORANGE MARMALADE", but to her great
(out) disappointment it was empty: she did not like to drop the jar for fear
(out) of killing somebody underneath, so managed to put it into one of the
(out) cupboards as she fell past it.
Has the above output (stdout).
./sgrep -n -B2 mouse alice.txt
(out) 78:tea-time. Dinah my dear! I wish you were down here with me! There are
(out) 79:no mice in the air, I'm afraid, but you might catch a bat, and that's
(out) 80:very like a mouse, you know. But do cats eat bats, I wonder?" And here
Has the above output (stdout).
./sgrep -c -B2 mouse alice.txt
(out) 1
Has the above output (stdout).
./sgrep -i rabbit alice.txt
(out) Down the Rabbit-Hole
(out) picking the daisies, when suddenly a White Rabbit with pink eyes ran
(out) so _very_ much out of the way to hear the Rabbit say to itself, "Oh
(out) time it all seemed quite natural); but when the Rabbit actually _took a
(out) had never before seen a rabbit with either a waistcoat-pocket, or a
(out) large rabbit-hole under the hedge.
(out) The rabbit-hole went straight on like a tunnel for some way, and then
(out) long passage, and the White Rabbit was still in sight, hurrying down
(out) turned the corner, but the Rabbit was no longer to be seen: she found
Has the above output (stdout).
./sgrep -v the dorothy.txt
by wagon many miles. There were four walls, a floor and a roof,
which made one room; and this room contained a rusty looking cooking
whirlwinds arose, mighty enough to crush any building in its path. It
Has the above output (stdout).