Advertisement

12.20.2005 at 07:47AM PST, ID: 21670668
[x]
Attachment Details

Replace text string using batch file

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2
Zone:

MS DOS

Tags:

replace, string, batch, file, text

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:~%pos%! %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=%mailboxnamechange%

CALL :STRIPLINENUMBER "%~1"

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

goto :EOF

:NOVALUE

call :STRIPLINENUMBER "%~1"

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

>>%outFile% echo %str%
Answered By: SteveGTR
Expert Since: 07/09/1999
Accepted Solutions: 1885
Computer Expertise: Guru
SteveGTR has been an Expert for 9 years 6 months, during which he has posted 7073 comments and answered 1885 questions. SteveGTR is just one of 1019 experts in the MS DOS Zone. 1 expert collaborated on this answer, which was graded an "A" by the asker.
 
 
20081119-EE-VQP-47