You mean something like this?
Code:
itsme@itsme:~/C$ cat intercept.c
#include <stdio.h>
#include <string.h>
int main(void)
{
char buf[BUFSIZ], *p;
int addnl;
while(fgets(buf, sizeof(buf), stdin))
{
if((p = strchr(buf, '\n')))
{
*p = '\0';
addnl = 1;
}
else
addnl = 0;
printf("Intercepted and passing on: %s\n", buf);
if(addnl)
puts(buf);
else
fputs(buf, stdout);
}
return 0;
}
Code:
itsme@itsme:~/C$ echo "foo bar baz"
foo bar baz
itsme@itsme:~/C$ echo "foo bar baz" | ./intercept
Intercepted and passing on: foo bar baz
foo bar baz
itsme@itsme:~/C$ cat foo.txt
this is some text
this is more text
itsme@itsme:~/C$ cat foo.txt | ./intercept
Intercepted and passing on: this is some text
this is some text
Intercepted and passing on: this is more text
this is more text
itsme@itsme:~/C$