Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
fillalph

Text Replacement Using A Batch

Recommended Posts


@clavicle

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

jaclaz

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...