批量替换2

replace2.bat

@echo off 
echo 开始替换! 
setlocal enabledelayedexpansion 
set TMPFILE2=%random%.reg 
set TMPFILE3=%random%.reg 
set TMPFILE4=%random%.reg 
if exist %TMPFILE2% ( del /f/q %TMPFILE2% ) 
if exist %TMPFILE3% ( del /f/q %TMPFILE3% ) 
if exist %TMPFILE4% ( del /f/q %TMPFILE4% ) 
reg export HKEY_CURRENT_USERSoftwarecvsntcvspass %TMPFILE2% 
if %ERRORLEVEL% EQU 0 ( 
type %TMPFILE2% > %TMPFILE3% 
for /f "tokens=*" %%m in ( 'findstr "scm3.***.cn" %TMPFILE3%' ) do ( 
if "%%m"=="" else ( 
for /f "tokens=*" %%l in ( %TMPFILE3% ) do ( 
set tmp2=%%l 
set "tmp2=!tmp2:scm3.***.cn:/repository=scm3.***.cn:/db2!" 
echo !tmp2!>>%TMPFILE4% 
) 
reg delete HKEY_CURRENT_USERSoftwarecvsntcvspass /va /f 
reg import %TMPFILE4% 
del /f/q %TMPFILE4% 
) 
) 
del /f/q %TMPFILE3% 
del /f/q %TMPFILE2% 
) 
set execdir=%~dp0 
cd /d %execdir% 
set TMPFILE=%random%.tmp 
if exist %TMPFILE% ( del /f/q %TMPFILE% ) 
for /r . %%i in ( Root ) do if exist "%%i" ( 
for /f "tokens=*" %%j in ( 'findstr "scm3.***.cn" "%%i"' ) do ( 
if "%%j"=="" else ( 
for /f "usebackq tokens=*" %%k in ( "%%i" ) do ( 
echo "%%i" 
set tmp=%%k 
set "tmp=!tmp:scm3.***.cn:/repository=scm3.***.cn:/db2!" 
echo !tmp!>>%TMPFILE% 
move /y "%%i" "%%i".bak 
move /y %TMPFILE% "%%i" 
) 
) 
) 
) 
endlocal 
echo 替换完毕! 
pause

replace2.sh

#!/bin/sh 
echo begin replace! 
if [ -f $HOME/.cvspass ] 
then 
if grep -E "scm3.***.cn" $HOME/.cvspass 
then 
sed -i.bak "s/scm3.***.cn:/repository/scm3.***.cn:/db2/" $HOME/.cvspass 
fi 
fi 
SAVEIFS=$IFS 
#IFS=$(echo -en "nb") 
IFS=" 
" 
exedir=`dirname $0` 
cd $exedir 
files=`find . -name Root -follow` 
for f in $files 
do 
g=`cat "$f"` 
h=`echo ${g##*@}` 
i=`echo ${h%%:*}` 
case $i in 
scm3.***.cn) 
echo "$f" 
sed -i.bak "s/scm3.***.cn:/repository/scm3.***.cn:/db2/" "$f" 
;; 
esac 
done 
IFS=$SAVEIFS 
echo replace finished!

你可能感兴趣的:(批量替换2)