I have the following lines of code

        BalancerMember http://server3:82 status=D
        BalancerMember http://server2:80 status=D

I want to search for entries with port 82 and then want to wipe out status=D. So , it will look like this

        BalancerMember http://server3:82

Tried this, but this will not work

  grep :82 app.conf | sed -i 's/status=D/ /'
  sed: no input files

I need the -i option with sed because I would like to make the change in file .

Any suggestions.


you can test a full sed solution

sed -i '/:82 /s/status=D//' file


  • /:82 / select line with 82
  • s/status=D/ replace status by
  • // nothing.
| improve this answer | |

Based on your sample data, this should work

awk '/:82 /{print $1,$2; next} {print}' inputfile

You can redirect the output of this into another file.

awk '/:82 /{print $1,$2; next} {print}' inputfile >> newfile

Generally I don't like to make changes to the original data if it can be helped.

| improve this answer | |

based on the given input

awk '$2~/:82$/{$NF=""}1' input.txt > output.txt
| improve this answer | |

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