Sign in to follow this  
Followers 0
fillalph

Text Replacement Using A Batch

21 posts in this topic

@clavicle

yay! :thumbup that's what I like to hear. Glad I could help

0

Share this post


Link to post
Share on other sites

@clavicle

yep, if you have problems, just post here the batch you made and I'll see what I can do.

jaclaz

0

Share this post


Link to post
Share on other sites
This should work for any text file.

replace "path\textfile" with the path and name of your original file.

replace "originaltext" with the text you want to replace.

replace "newtext" with the text you want instead.

for /f %%L in (path\textfile) DO (
if "%%L"=="originaltext" (
 echo newtext>>path\temp.TMP
) ELSE (
 echo %%L>>path\temp.TMP
)
)
copy /Y path\temp.TMP path\textfile

I have tried to make a batch file that searches an extracted help file webpage rename it to a text. Then do a find and replace the links in the string. CMD file is called 2 in the attached zip file.

@echo off
Setlocal
set NAME=ntcmds
set FOLDER=cmds

echo Deleting old folder if exists.
IF EXIST %NAME% RD /S /Q %NAME%

Echo Decompiling %NAME% Help file
hh.exe -decompile .\%NAME%\ %WINDIR%\Help\%NAME%.chm

Echo Moving all other files to %FOLDER%
md %NAME%\%FOLDER%
cd %NAME%
move *.* %FOLDER%
Move .\%FOLDER%\%NAME%.htm .\%NAME%.htm


ren %NAME%.htm %NAME%.txt
find "MS-ITS:%NAME%.chm::/" %NAME%.txt /c

The last line of the code is what I want to find and replace. I Then removed it and added see below.

I wanted to change the links in the webpage to see the wepages in the folder below it.

for /f %%L in (%NAME%.txt) DO (
if "%%L"=="MS-ITS:%NAME%.chm::/" (
echo %FOLDER%\>>.\temp.TMP
) ELSE (
echo %%L>>.\temp.TMP
)
)
copy /Y temp.TMP %NAME%.txt

I used the code above to changed the find and replace to be what I want to replace etc.

find = MS-ITS:%NAME%.chm::/

Replace with = %FOLDER%\ or cmds\ but prefer to use the varible

But it doesn't work all that is in the temp file is the first few charaters from each line.

I don't know much about the for command and would like help in understanding it.

0

Share this post


Link to post
Share on other sites

Is it possible to replace some strings contained between two other ones?

For example: BEGINstringEND --> BEGINnew_stringEND

Thanks

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.