批量替换3

replace3.bat

@echo off 
set mail=zbwangjian 
set mail2=wangjian1.***.cn 
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% >nul 2>nul 
if %ERRORLEVEL% EQU 0 ( 
type %TMPFILE2% > %TMPFILE3% 
for /f "tokens=*" %%m in ( 'findstr ":%mail%: :%mail%@" %TMPFILE3%' ) do ( 
if "%%m"=="" else ( 
for /f "tokens=*" %%l in ( %TMPFILE3% ) do ( 
set tmp2=%%l 
set "tmp2=!tmp2::%mail%:=:%mail2%:!" 
set "tmp2=!tmp2::%mail%@=:%mail2%@!" 
echo !tmp2!>>%TMPFILE4% 
) 
reg delete HKEY_CURRENT_USERSoftwarecvsntcvspass /va /f 
reg import %TMPFILE4% 
del /f/q %TMPFILE4% 
) 
) 
if exist %TMPFILE3% ( del /f/q %TMPFILE3% ) 
if exist %TMPFILE2% ( 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 ":%mail%: :%mail%@" "%%i"' ) do ( 
if "%%j"=="" else ( 
for /f "usebackq tokens=*" %%k in ( "%%i" ) do ( 
echo "%%i" 
set tmp=%%k 
set "tmp=!tmp::%mail%:=:%mail2%:!" 
set "tmp=!tmp::%mail%@=:%mail2%@!" 
echo !tmp!>>%TMPFILE% 
move /y "%%i" "%%i".bak 
move /y %TMPFILE% "%%i" 
) 
) 
) 
) 
endlocal 
echo 替换完毕! 
pause

replace3.sh

#!/bin/sh 
mail=zbwangjian 
mail2=wangjian1.***.cn 
echo begin replace! 
if [ -f $HOME/.cvspass ] 
then 
if grep -E ":$mail:|:$mail@" $HOME/.cvspass 
then 
sed -i.bak "s/:$mail:/:$mail2:/;s/:$mail@/:$mail2@/" $HOME/.cvspass 
fi 
fi 
SAVEIFS=$IFS 
IFS=" 
" 
exedir=`dirname $0` 
cd $exedir 
files=`find . -name Root -follow` 
for f in $files 
do 
echo "$f" 
sed -i.bak "s/:$mail:/:$mail2:/;s/:$mail@/:$mail2@/" "$f" 
done 
IFS=$SAVEIFS 
echo replace finished!

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