Replace text string using batch file

Replace text string using batch file

Asked by qvhit in MS DOS

Tags: , , , ,

Previously I recieved help from SteveGTR to create the batch file below which changes the UserName variable into a different format then calls on a standard PRF file and creates a new one with the correct UserName format.  The problem was that the batch file replaced the Value for MailboxName in each section and not just in section 4 where it was needed.  So the only way I can think to correct this issue is to make the MailboxName in section 4 unique and for the batch file to look for that instead.

So I changed the PRF (in section 4) and the batch file from MailboxName to MailboxNameChange and it has the desired effect.  Problem is that I now need the same batch file to look for anything in the output file by the name of MailboxNameChange and convert it back to MailboxName so that I can run the PRF correctly.

Thanks


@echo off

setlocal enabledelayedexpansion

set un=%~1

if "%un%"=="" set un=%username%

set /a pos=1

:NEXTCHAR

if "!un:~%pos%,1!"=="" echo Parsing error&goto :EOF

for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  if "!un:~%pos%,1!"=="%%a" (
    set /a pos+=1
    goto NEXTCHAR
  )  
)

set /a pos-=1

set MailboxNameChange=!un:~%po s%! %un:~0,1%

REM ** Change this part
set inFile="c:/prf/v1.prf"
set outFile="C:/prf/V1a.prf"
set workFile=" temp .txt"


>%workFile% find /N /V "_STM_STM_" %inFile%

if exist %outFile% del %outFile% >NUL

set /a lineCnt=0

for /f "skip=2 tokens=1,2 delims==" %%a in ('type %workFile% 2^>NUL') do call :PROCESS "%%a" "%%b"

if exist %workFile% del %workFIle% >NUL

echo Output in %outFile%

goto :EOF

:STRIPLINENUMBER

set str=%~1

:SLN_NEXTCHAR

if "%str:~0,1%"=="]" goto GOTLINE

set str=%str:~1%
goto SLN_NEXTCHAR

:GOTLINE

set str=%str:~1%

goto :EOF

:PROCESS

set /a lineCnt+=1

echo Processing line %lineCnt%

if "%~2"=="" goto NOVALUE

set valuePart=%~2

for /f "tokens=2 delims=] " %%a in ('echo %~1 2^>NUL') do if "%%a"=="MailboxNameChange" set valuePart=%mailboxnamechan ge%

CALL :STRIPLINENUMBER "%~1"

>>%outFile% echo %str%=%valuePart%

goto :EOF

:NOVALUE

call :STRIPLINENUMBER "%~1"

if "%str%"=="" (
  echo.>>%outFile%
  goto :EOF
)

>>%outFile% echo %str%
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值