0

Hi all,
I have a proplem when embed shell into C code by Sytem() command.
There is my code:
char acCommand[512];
acCommand[0] = '\0';
sprintf(acCommand,"sed \'s/\<UDN\>\<\/UDN>/\<UDN\>%s\<\/UDN\>\/g\' %s > %s", initParam.UDN, "/tmp/web/dmr.xml", "/tmp/web/dmr.xml.tmp");
printf("[%s]", acCommand);
system(acCommand);

and below is output after compiling:
sed 's/<UDN></UDN>/<UDN>uuid:b346ee95-93b3-4922-a132-cf72762b9318</UDN>/g' /tmp/web/dmr.xml > /tmp/web/dmr.xml.tmp]
sed: bad option in substitution expression
I thinks the bad option is <\/UDN\>
I have tried to do something but it still doesn't work, same as above problem.

Could you please help me to solve this problem.
Thanks.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Dwiliam
0

Use ";" instead of "/" as the sed separators.
instead of

s/<UDN></UDN>/<UDN>uuid:b346ee95-93b3-4922-a132-cf72762b9318</UDN>/g

use

s;<UDN></UDN>;<UDN>uuid:b346ee95-93b3-4922-a132-cf72762b9318</UDN>;g

as that "/" in "</UDN>" is garbling your sed command.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.