The Unix grep program finds lines that match a regular expression. Implement a java version of grep.

Make this implementation run faster by running it in a multithreaded way. Split each input file into two equal-sized regions, and look for instances of the regular expression in each region, in a separate thread. The second thread should not output any lines until the first thread is done; instead, it should simply record the matching lines internally, so that it can operate in parallel with the first thread, and wait until the first thread is done before outputting anything based on its records. If an input line straddles the boundary between the two regions, or begins at the very start of the second region, the first thread (and not the second thread) should output the line.

Measure the performance of the original Java grep (non-parallel), compared to your modified (parallel) version, and compare both to GNU grep.

If you have access to the ualbany Unix environment you may run the grep command as follows:

LC_ALL='C' time grep -n 'word to find' /path/to/file/abc.txt

This will print the timing for you

You may add timings directly in your java code in your main method (beginning and at end of scope)

Make sure your JAVA versions expect command line args in same format as the grep command does (shown above). For now, only the above type of args need to be handled

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.