Note that there are some explanatory texts on larger screens.

plurals
  1. POShell: How to replace something of a text with the saved variable value
    primarykey
    data
    text
    <p>I saved a value by shell command: For example:</p> <pre><code>timeoutvalue=`echo "timeout=2.0"` </code></pre> <p>And I have to grep the value of timeout from another text, and replace it with this timeoutvalue. For example, the text is egtest:</p> <pre><code>&lt;host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" timeout=4.0/&gt; </code></pre> <p>I want to grep the value of timeout from the above text and replace the value of <code>timeout=4.0</code> by <code>timeout=2.0</code>(the value I saved as variable by shell command).</p> <p>My problem is: (1)for a simple test, I want to replace the value of timeout=4.0 with $timeoutvalue. So my command is:</p> <p><code>sed 's/timeout=4.0/$timeoutvalue/g' egtext</code>.</p> <p>But it seems the text become:</p> <pre><code>&lt;host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" $timeoutvalue/&gt; </code></pre> <p>Could anybody tell me why it is wrong?</p> <p>(2)For this problem, I have to first grep <code>timeout=4.0</code> from the text, and replace the value <code>4.0</code> to the saved variable value(in my example:2.0). I thought but I don't know which command to use to realize this(awk? sed?) Because the filed of the text isn't certain,(for example, in this text, timeout is in <code>$5</code>, but maybe in another text, it maybe changed into <code>$6</code>). I mean it may be changed into:</p> <pre><code>&lt;host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" type="onebox" timeout=4.0/&gt; </code></pre> <p>Could anybody help me with this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload