用 sed 来替换



用sed来替换

遍历目录替换

sed -i "s/要查找的字符串/替换字符串/g" `grep "要查找的字符串" -rl 目录`
sed -i "s/Generated by CoffeeScript 1.6.3/created by bigzhu/g" `grep "Generated by CoffeeScript 1.6.3" -rl ./`

  • 例子

sed -i "s/log = logger.initlog(__file__.replace('.py', '') + '.log')/log = logger.initlog()/g" `grep "log = logger.initlog(__file__.replace('.py', '') + '.log')" -rl ./`
sed -i "s/from common.public_db import common.public_db/from common.public_db import daemonDB/g" `grep "from common.public_db import common.public_db" -rl ./`
sed -i "s/@common.public_db.daemonDB/from common.public_db import common.public_db\[email protected]/g" `grep "@common.public_db.daemonDB" -rl ./`

sed -i "s/import oper/import common/g" `grep "import call_back" -rl ./`

sed -i "s/public_db\./common.public_db./g" `grep "public_db\." -rl ./`
sed -i "s/exp\./common.exp./g" `grep "exp\." -rl ./`
sed -i "s/public\./common.public./g" `grep "public\." -rl ./`
sed -i "s/logger/common.logger/g" `grep "logger" -rl ./`
sed -i "s/import sms/import common.sms as sms/g" `grep "import sms" -rl ./`
sed -i "s/import web_util/import public.web_util as web_util/g" `grep "import web_util" -rl ./`
sed -i "s/import public.web_util as web_util/import common.web_util as web_util/g" `grep "import public.web_util as web_util" -rl ./`
sed -i "s/except:/except Exception:/g" `grep "except:" -rl ./`
sed -i "s/ServicePrivilegeInfo/ServicePrivilege/g" `grep "ServicePrivilegeInfo" -rl ./`
sed -i "s/ServerManagerPlay/ServiceManager/g" `grep "ServerManagerPlay" -rl ./`
sed -i "s/ServiceManager/ArcGisServiceManager/g" `grep "ServiceManager" -rl ./`
sed -i "s/ServerManager/ServiceManager/g" `grep "ServerManager" -rl ./`

sed -i “s/ServiceManager/ArcGisServiceManager/g” grep "ServiceManager" -rl ./

当前目录替换

sed -i "s/from common import logger\nlog = logger.initlog()/from common.logger import log/g" ./*.py

sed -i "s/mem.mc/mem/g"  ./*.py














sed -i "s/mem.mc/mem/g"  ./*.py
sed -i "s/log = logger.initlog(__file__.replace('.py', '') + '.log')/from common import logger\nlog = logger.initlog(__file__.replace('.py', '') + '.log')/g"  ./*.py

sed -i "s/mem.mc/mem.cm/g"  ./*.py
sed -i "s/isUserLogged/isUserLoggedAndToLogin/g"  ./*.py

sed -i "s/web.maintain.serviceManager.ServerManagerPlay/ServerManagerPlay/g" ./*.
sed -i "s/servicemanager/serviceManager/g" 

sed -i "s/=/ = /g" ./*.py


sed -i "s/=/ = /g" ./*.py
sed -i "s/  =  / = /g" ./*.py
sed -i "s/=  =/==/g" ./*.py
sed -i "s/! =/!=/g" ./*.py
sed -i "s/+ =  /+= /g" ./*.py
sed -i "s/+ =/+=/g" ./*.py

sed -i "s/ = utf-8/=utf-8/g" ./*.py



sed -i "s/\[/\[\[/g" ./*.wiki
sed -i "s/\]/\]\]/g" ./*.wiki


sed -i "s/\]\]\]\]/\]\]/g" ./*.wiki
sed -i "s/\[\[\[\[/\[\[/g" ./*.wiki

sed -i "s/select_qry/select/g" ./*.py
sed -i "s/BSS_ORG/GET_BSS/g" ./*
sed -i "s/throw domain_error(m_sErrorInfo)/THROW_DOMAIN(m_sErrorInfo)/g" ./CInDistri.cpp

sed -i "s/throw domain_error(m_sErrorInfo)/THROW_DOMAIN(m_sErrorInfo)/g" ./*.cpp ./*.h

++其他
sed -i "s/datetime.now()/'\/\sysdate'/g" ./adjust.py
sed -i "s/im_exception/exp/g" ./*.py
sed -i "s/main_im/im/g" ./*.tac
sed -i "s/main_im/im/g" ./*.py

sed -i "s/\[\[/\[/g" ./*.wiki

sed -i "s/\]\]/\]/g" ./*.wiki

#替换![pic](空格)
sed -i "s/\[ \]//g" ./*.wiki
#替换![pic](星号)
sed -i "s/\![pic](\*\)//g" ./*.wiki
#替换zim信息
sed -i "s/Content-Type: text/x-zim-wiki//g" ./*.wiki

sed -i "s/assembleFromSQL/assembleFromSql/g" ./*.cpp

sed -i "s/forServer.h/public.h/g" ./*.cpp

sed -i "s/setErrorFMLServ/setErrorFML/g" ./*.h
sed -i "s/stringToP/strToP/g" ./*.cpp

sed -i "s/mainUpdate2/update/g" ./*.cpp ./*.h

sed -i "s/INVOICE_DISTRI_ID/INVOICE_DISTRI_ID/g" ./*.cpp ./*.h

sed -i "s/E_invoice_distri/distri/g" ./*.cpp ./*.h

sed -i "s/INVOICE_DISTRI_ID/DISTRI_ID/g" ./*.cpp ./*.h

sed -i "s/invoice_distri_id/distri_id/g" ./*.cpp ./*.h

sed -i "s/P_STRING/string/g" ./*.cpp ./*.h
sed -i "s/strToP//g" ./*.cpp ./*.h
sed -i "s/setFML2/setFML/g" ./*.cpp ./*.h

sed -i "s/getFMLData/transFML/g" ./*.cpp ./*.h
sed -i "s/getStrFromM/getFMLValue/g" ./*.cpp ./*.h

sed -i "s/noMust/notMust/g" ./*.cpp ./*.h

sed -i "s/getStrKeyData/getFMLData/g" ./*.cpp ./*.h
sed -i "s/m_mSendFml/m_mSendFML/g" ./*.cpp ./*.h

sed -i "s/domain_error e/std::exception \&e/g" ./*.cpp ./*.h
sed -i "s/std::exception std::exception \&ee/std::exception \&e/g" ./*.cpp ./*.h



sed -i "s/P_STRING/sendbuf/g" ./*.cpp ./*.h