>but I can't think of how to replace the word with the other one.
You can hope like crazy that the string you're looking for is the whole of the buffer, or you can use a replace type function similar to below:
Code:
Tue Sep 23 9:37:12am
sangut: ~/misc
> cat rp.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *replace(const char *s1, const char *find, const char *repl) {
char *rs;
char *loc;
int slen = strlen(s1);
int flen = strlen(find);
int rlen = strlen(repl);
if ((loc = strstr(s1, find)) != NULL) {
if ((rs = calloc(slen - flen + rlen + 1, sizeof *rs)) == NULL)
return NULL;
strncpy(rs, s1, loc - s1);
strcat(rs, repl);
strcat(rs, loc + strlen(find));
return rs;
}
return NULL;
}
int main(int argc, char *argv[]) {
char buffer[BUFSIZ];
char *fixed;
if (argc != 3) {
fprintf(stderr, "usage: % rp <find> <replace>\n");
exit(EXIT_FAILURE);
}
while (fgets(buffer, sizeof buffer, stdin) != NULL) {
if ((fixed = replace(buffer, argv[1], argv[2])) != NULL)
puts(fixed);
else
puts(buffer);
}
return 0;
}