Replacing pattern

Hi,

I have a file which contains the below data. I want to search for a pattern server="http://bushby.mis.amat.com:12440" and remove it from the file.

Please let me know how can i do this.

<Object name="reverse-proxy-/endeavour/">
ObjectType fn="http-client-config" timeout="1800"
ObjectType fn="block-auth-cert"
ObjectType fn="block-user-dn"
ObjectType fn="block-issuer-dn"
ObjectType fn="block-keysize"
ObjectType fn="block-via"
ObjectType fn="block-ssl-id"
ObjectType fn="block-secret-keysize"
ObjectType fn="block-proxy-agent"
ObjectType fn="block-ip"
ObjectType fn="block-cipher"
ObjectType fn="block-proxy-auth"
Route fn="set-origin-server" server="http://bearcat.mis.amat.com:12440" server="http://bushby.mis.amat.com:12440" server="http://bearcat.mis.amat.com:11440"
server="http://bushby.mis.amat.com:11440"
</Object>

<Object ppath="http:*">
Service fn="proxy-retrieve" method="*"
</Object>

<Object name="reverse-proxy-/connect/">
ObjectType fn="http-client-config" timeout="1800"
ObjectType fn="block-proxy-agent"
ObjectType fn="block-proxy-auth"
Route fn="set-origin-server" server="http://bearcat.mis.amat.com:12440" server="http://bushby.mis.amat.com:12440" server="http://bearcat.mis.amat.com:11440"
server="http://bushby.mis.amat.com:11440"
</Object>

<Object name="reverse-proxy-/liferay/">
ObjectType fn="http-client-config" timeout="1800"
Route fn="set-origin-server" server="http://bearcat.mis.amat.com:12440" server="http://bushby.mis.amat.com:12440" server="http://bearcat.mis.amat.com:11440"
server="http://bushby.mis.amat.com:11440"
</Object>
$ ruby -pne 'gsub(/http:\/\/bushby\.mis\.amat\.com:12440/,"")' file

If you want to remove the entire line containing that string, the

cp file file.backup
cat file | grep -v "http://bushby.mis.amat.com:12440"  > file.new
sed 's|server="http://bushby.mis.amat.com:12440"||g' file

cat is useless.:slight_smile:

And in this case, maybe fgrep is more suitable.

fgrep -v "http://bushby.mis.amat.com:12440" infile

by sed with -i option, you can update the infile directly.

sed -i '/"http:\/\/bushby.mis.amat.com:12440"/d' infile

Hi,

Thanks for the help guys.

If i want to add this server back to the same place. is there a option?

Then you need backup your file, before update it .

sed -i`date +%Y%m%d` '/"http:\/\/bushby.mis.amat.com:12440"/d' infile