0

This question already has an answer here:

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.

marked as duplicate by don_crissti, GAD3R, Jeff Schaller, Anthony Geoghegan, techraf Dec 9 '16 at 12:09

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.

3

you can test a full sed solution

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

where

  • /:82 / select line with 82
  • s/status=D/ replace status by
  • // nothing.
0

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.

0

based on the given input

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

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