bash - Replace a variable with text (sed) -


i have find specific text in file , replace text new text.

the contents of 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 gives me error:

sed: -e expression #1, char 2: unterminated `s' command 

note: want update value of each of variable i.e. servers=4 should replaced servers=5.

please me figure out solution.

thanks.

the output of grep ends newline character. sed expects whole command on 1 line or escaping line breaks.

however, can achieve complete task sed only:

sed -i 's/^servers=[0-9]*$/servers=5/' /path/to/file 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -