6

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) .

16

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.

| improve this answer | |

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