Reputation: 779
I am processing an XML file with sed. The content of the file to be replaced is bellow.
<NS1:myService>
<NS1:code>1</NS1:code>
<NS1:timestamp>Event_Time_Stamp</NS1:timestamp>
<NS1:log>
<NS1:logLevel>some_level</NS1:logLevel>
<NS1:loggerName>log_back</NS1:loggerName>
<NS1:message>loggable_message</NS1:message>
<NS1:node>none</NS1:node>
<NS1:host>my_host</NS1:host>
</NS1:log>
</NS1:myServices>
I need to replace contents of the node with the my text. It works every time when variable which contains my text has NO space. As soon as there is space sed throws an error.
sed: -e expression #1, char 120: unterminated `s' command
Here is how I create my message in my script
text="APPLICATION:\t\t$app\n"
text=$text"RECEIVER:\t\t$receiver\n"
text=$text"LOGGABLE MESSAGE:\t$message\n"
text=$text"SENDER:\t\t$sender\n"
text=$text"DATE CREATED:\t$created\n"
I use the following sed statement to do my replacements
sed -i 's|<NS1:message>.*<|<NS1:message>'$text'<|g' $workfile
However the above command breaks every time on space. How can I escape white space so sed would process it just like any other character?
Upvotes: 1
Views: 3803
Reputation: 779
As soon as I posted the question I figured it out. I needed yo use "
Command looks like this
sed -i 's|<NS1:message>.*<|<NS1:message>'"$text"'<|g' $workfile
Upvotes: 2