A
A. N. O. N.
Hello friends
I need to write a shell utility. It will read the contents of a file,
perform a string replacement on those contents, and print out the result.
It will work similarly to grep except that it performs string replacement
in addition to matching, and it does not support regular expressions or
reading from standard input. But because of the similarities, our command
will be called strep (not to be confused with "strep throat").
Here is how the strep command works. Imagine a file named test.txt
contains the following lines:
foo a b c d foo e
A foo B
0 foo 1 2 foo
We could replace all occurrences of foo with goo as follows (assume we
are in the same directory containing foo.txt):
bash$ strep foo goo test.txt
goo a b c d goo e
A goo B
0 goo 1 2 goo
bash$
There are a couple of things that should be noted. First, the arguments
to strep are passed via the command line and can be accessed through the
variable argv in main. The user must enter three arguments after the
command. The first argument is the string to match (e.g., foo), the
second is the replacement string (e.g., goo), and the third is the file
to read from (e.g., test.txt).
The second thing to note with regard to the example above is that strep
replaces all occurrences of foo with goo on a particular line, not just
the first occurrence (although it will not replace a single string that
spans multiple lines).
Please send me full code for strep.c ASAP thanks.
PS this is not homework
I need to write a shell utility. It will read the contents of a file,
perform a string replacement on those contents, and print out the result.
It will work similarly to grep except that it performs string replacement
in addition to matching, and it does not support regular expressions or
reading from standard input. But because of the similarities, our command
will be called strep (not to be confused with "strep throat").
Here is how the strep command works. Imagine a file named test.txt
contains the following lines:
foo a b c d foo e
A foo B
0 foo 1 2 foo
We could replace all occurrences of foo with goo as follows (assume we
are in the same directory containing foo.txt):
bash$ strep foo goo test.txt
goo a b c d goo e
A goo B
0 goo 1 2 goo
bash$
There are a couple of things that should be noted. First, the arguments
to strep are passed via the command line and can be accessed through the
variable argv in main. The user must enter three arguments after the
command. The first argument is the string to match (e.g., foo), the
second is the replacement string (e.g., goo), and the third is the file
to read from (e.g., test.txt).
The second thing to note with regard to the example above is that strep
replaces all occurrences of foo with goo on a particular line, not just
the first occurrence (although it will not replace a single string that
spans multiple lines).
Please send me full code for strep.c ASAP thanks.
PS this is not homework