Be sure you have read chapter 9.
Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu, with each file as an attachment. Please use a subject line that mentions the course and the assignment (e.g., ``csci 1320 homework 6'' or ``CS1 hw6''). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.
Hello world!
There is a German word for worldview that I have forgotten.
World without end.
Goodbye!
and you search for world, the first and second lines match. (It's easiest to do the match in a case-sensitive way, so the third line does not match.) grep by default prints each matching line preceded by the filename, so if the above text is in a file called input1.txt, and input2.txt is a file containing the lines
world without end
end of the world
grep world input1.txt input2.txt produces the output:
input1.txt:Hello world!
input1.txt:There is a German word for worldview that I have forgotten.
input2.txt:world without end
input2.txt:end of the world
Like grep, your program should get the text to search for and the names of one or more files from its command-line arguments. So for example if you call your program simple-grep.scala, scala simple-grep.scala world input1.txt input2.txt should produce the same output as above. Your program should print an error message if there are not at least two command-line arguments. It's okay to assume that the files specified actually exist (and accept that if they don't, your program will crash); if that bugs you and/or you want an extra-credit point, you can write your program to instead print an error message about files that don't exist.
Hints:
hello world from me
world hello hello world
just a line
hello!
changing ``hello'' to ``HELLO'' should produce a file that contains:
HELLO world from me
world HELLO HELLO world
just a line
HELLO!
Your program should get the names of the input and output files from command-line arguments and prompt the user to enter oldtext and newtext.
Hints:
For extra credit (up to 5 points), have your program do an interactive search and replace. You have two options (the second of which is more difficult and therefore worth more points):