Reputation: 361
I have to find a specific text in the file and then replace that text with some new text.
The contents of the file are:
host=100
servers=4
clients=70
I have tried this:
var=$(grep "servers=" /path/to/file)
sed -i "s/${var}/servers=5/g" /path/to/file
But it gives me the error:
sed: -e expression #1, char 2: unterminated `s' command
Note: All I want is to update the value of each of the variable i.e. servers=4 should be replaced by servers=5.
Please help me figure out the solution.
Thanks.
Upvotes: 0
Views: 71
Reputation: 6695
The output of grep
ends with a newline character. sed
expects the whole command on one line or escaping line breaks.
However, you can easily achieve the complete task with sed
only:
sed -i 's/^servers=[0-9]*$/servers=5/' /path/to/file
Upvotes: 3