![]() ![]() sgrep fish WONDERFUL day for fishing one fish two FISH, red fish blue FISH $ Great! Two lines, as should be expected. First, let's do a simple search for all the lines containing the word "fish": $ cat words.txt |. Run this to get your executable: $ make Let's also assume that you have a file in this same directory named words.txt and it has the following contents: please excuse this fooh soups specification WONDERFUL day for fishing zoos zoologists zoomies one fish two FISH, red fish blue FISH Lets try testing out our sgrep program. Assume that you have written the program correctly, and that you created a makefile to compile it to an output executable file named sgrep. Lets walk through a few examples of how the program should behave, which will hopefully give you a better idea of how it should be implemented. This program may assume that the max line width is 200 characters wide, and it should not assume a maximum number of input lines. The input may have multiple lines, so the program should continue reading input until it receives a EOF line indicating that the program may stop processing input lines and may exit / return. The program will get its input from standard in. sgrep -e a.z Print out every line containing a subsequence that starts with “a”, ends with "z", and contains two characters in-between from words.txt sgrep -e b#z Print out every line containing a subsequence that starts with “b" and ends with "z" from stuff.txt $ cat words.txt |. sgrep -i -o ee Print out every occurrence of the string "ee" "Ee" "E" or "EE" from words.txt $ cat stuff.txt |. sgrep orange Print out every line containing the string "orange" from todo.txt $ cat words.txt |. A few examples of valid ways to run this program (after being compiled to sgrep): $ cat todo.txt |. The search results should be printed to standard output. The search will act on whatever is fed to the program via standard input, and should continue to search until EOF is reached. The program should support the arguments being specified in any order. More information about these patterns will be shown later in the specification. The search term can either function in a literal search (search of the exact string the user provides) or, with the -e flag, the user can give a pattern (one search term that can match multiple strings). The other command-line argument will be some sequence of ascii-characters that represent what to search for. The default behavior will be to search for the exact search string provided. The default behavior will be to search case-sensitive. The default behavior of sgrep will be to print the whole line if a match is found. The program should support these three flag arguments in any position on the command line: -0 Only print the exact part(s) of each line that matches the search, not the entire line. ![]() This program should expect between 0 and 3 flag arguments, and one additional argument which specifies what to search for. Your program should function similarly, but it does not have to support as many arguments and features compared to the regular command. The grep command can be used for searching for strings and patterns from standard input. As with PA3, I recommend spending a bit of time playing around with the command and reading the man page ($ man grep) for the regular command before starting this program. You should have already used this command by now, perhaps for PA1. ![]() This program will be a simplified version of the grep command that can be found on many UNIX systems, including lectura. SGrep (Simple Grep) You should write a C program named sgrep.c.
0 Comments
Leave a Reply. |