2012-06-24 91 views
1

我有這樣的文件,我想使用sed替換$GLOBALS['SERVER_MEMCACHED']='localhost';$GLOBALS['SERVER_MEMCACHED']='mydomain.com';使用sed替換文本文件中的「localhost」

如何做到這一點?我不想更換DB_HOST。

<?php 
$GLOBALS['DB_HOST']='localhost'; 
$GLOBALS['DB_NAME']='database'; 
$GLOBALS['DB_LOGIN']='login'; 
$GLOBALS['DB_PASSWORD']='password'; 
$GLOBALS['PORT_MYSQL']='3306'; 
$GLOBALS['PORT_MYSQLI']='3306'; 
$GLOBALS['SERVER_MEMCACHED']='localhost'; 
$GLOBALS['PORT_MEMCACHED']='11211'; 
$GLOBALS['CACHE_TIME']=600; 
?> 

回答

2
sed -i '/SERVER_MEMCACHED/s/localhost/mydomain.com/' input 
+0

謝謝!有用 :) – Spacedust