sed替换

sed 替换原文件内容(Linux、)
sed -i 's/xxxx/aaaa/g' replacefile

sed 替换原文件内容(Mac)
sed  -i backup_prefix 's/xxxx/aaaa/g'  replacefile 


mac sed delete line
eg: sed -i "" '/AllVideoClkUrlSeparat/d' dsp_server.conf.ali
 #To remove the line and print the output to standard out:

sed '/pattern to match/d' ./infile
#To directly modify the file:

sed -i '/pattern to match/d' ./infile
#To directly modify the file (and create a backup):

sed -i.bak '/pattern to match/d' ./infile
#For Mac OS X users:

sed -i '' '/pattern/d' ./infile

 



sed find line and replace
function  testmongo() {
dsp;
n=`grep -i   '^Mongo' conf/xxx.conf   -n  |awk -F":" '{print $1}'`
sed -i "$n c  Mongo= \"52.7.24.20:27017\" " conf/xxx.conf > a.conf

grep -i   '^Mongo' conf/xxx.conf   -n  |awk -F":" '{print $1}'

mgs ;
sleep 0.5
ers
}

function onlinemongo() {
dsp;
n=`grep -i   '^Mongo' conf/xxx.conf   -n  |awk -F":" '{print $1}'`
Mongo="52.200.91.191:27017,52.45.155.109:27017"
sed -i "$n c  Mongo= \"$Mongo\" " conf/xxx.conf > a.conf
mgs ;
sleep 0.5
ers
}

 

posted on 2018-03-13 14:27  iokde.com  阅读(229)  评论(0)    收藏  举报

导航