5

This question already has an answer here:

I have a code block as follows in a file:

BalancerMember http://snode1:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode1
BalancerMember http://snode2:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode2

I want to search for all lines which had tc_ keyword and add status=D at the end of those lines. So, the above entries will become like this

BalancerMember http://snode1:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode1 status=D
BalancerMember http://snode2:80 min=1 max=1000 loadfactor=1  timeout=30 keepalive=on route=tc_snode2 status=D

I am using the following command to achieve this:

sed -i '/tc_/a status=D' app.conf

But I can see status=D is being after a newline. I don't want a newline for this. It should be appended with a '' (space) .

marked as duplicate by don_crissti, Satō Katsura, GAD3R, Tomasz, HalosGhost Dec 7 '16 at 17:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

14

try

sed  -e '/tc_/s/$/ status=D/'

where

  • /tc_/ on line where tc_ is found,
  • s substitute,
  • /$ end of line,
  • / status=D/ by this string

if it looks OK, add -i to edit in place.

Not the answer you're looking for? Browse other questions tagged or ask your own question.