Hello,
I am going nuts with trying to get the following to work:
This is what I intend to do: I have a line in /etc/syslog.conf which I
need to delete based on ip-address provided to me in a variable.
Forgetting that variable part for now .. this is what i want in the
grep command:
grep -suob "\*\.\* *...@172.23.62.12"
to get the byte offset to the line
*.* @172.23.62.12
The entire goal is to delete this line (and not just comment it) from
the file. I am a complete newbie to Sed but I'd ahve to create a new
file and rename it to /etc/syslog.conf? .. kinda not neat?
So, trying to use popen.
Sub-Goal:
FILE *fp = popen ("/bin/grep -soub \"\\*\\.\\* *...@172.23.62.12\"
/etc/syslog.conf", "r");
/* Just two characters */
[\"] is a single character. So is [\\].
Now the issue is that 172.23.62.12 is a variable, so I tried to use
sprintf/strcpy like this:
strcpy (buff, "\"/bin/grep -soub \\\"\\\\*\\\\.\\\\*
*...@172.23.62.12\\\"
/etc/syslog.conf\"");
OR
sprintf (buff, "\"/bin/grep -soub \\\"\\\\*\\\\.\\\\*
*...@172.23.62.12\\\" /etc/syslog.conf\"");
Followed by:
FILE *fp = popen (buff, "r");
But I get an error on grep indicating that the correct commands to grep
are not getting passed!
I seem to realize that both strcpy and sprintf above copy the string as
/* FOUR characters :-( */
[\]["] and [\]][\] -- which are 4 different characters as opposed to
two "escaped" characters above.
What am I doing wrong?
Any help deeply appreciated!
Thanks!