Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7677355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:24:14+00:00 2026-05-31T17:24:14+00:00

How would I change the below script to edit the original file instead of

  • 0

How would I change the below script to edit the original file instead of generating a new one? Also, how would I make this script execute on all .html files in the same directory instead of having to specify one file at a time.

@echo off
setlocal EnableDelayedExpansion
call :processFile < template.html > final.html
goto :EOF

:processFile
   set line=EOF
   set /P line=
   if "!line!" == "EOF" goto :EOF
   set X=
   set "lineNoGen=!line:Gen_1_=$!"
   if "!lineNoGen!" neq "!line!" (
      for /F "tokens=1-3 delims=$" %%a in ("!lineNoGen:Gen.1.=$!") do (
         set "beforeGen=%%a"
         set "betweenGens=%%b"
         set "afterGen=%%c"
         set "X=!betweenGens:~0,1!"
         set /A Xm1=X-1, Xp1=X+1
         echo !beforeGen!Gen_1_!Xm1!!betweenGens:~1!Gen.1.!Xm1!!afterGen:~1!
      )
   )
   echo !line!
   if defined X (
       echo !beforeGen!Gen_1_!Xp1!!betweenGens:~1!Gen.1.!Xp1!!afterGen:~1!
   )
goto :processFile
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:24:15+00:00Added an answer on May 31, 2026 at 5:24 pm

    As far as I know, there is no inplace option for Windows Batch.
    I would just use a temporary file:

    call :processFile < template.html > tmp_file
    move tmp_file template.html
    

    If Unix/Linux user are interested in an answer:

    There is Colin Watson’s sponge (packed for Debian in the moreutils package):

    theConvertProgram < template.html | sponge template.html
    

    See https://unix.stackexchange.com/a/29744/15241 for more information.

    Solution with temporary file:

    theConvertProgram < template.html > tmp_file
    mv tmp_file template.html
    

    improved version with mktemp:

    TEMP_FILE="$(mktemp)"
    theConvertProgram < template.html >  "$TEMP_FILE"
    mv "$TEMP_FILE" template.html
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I use $(this) instead of the full selector in the code below
How would I change the initial templates created by Xcode when creating a new
How would one change the view on the screen programmatically in an iPhone app?
How would I change the following markov script to treat capitalized and lowercase words
What is the correct way to do this? For example, how would I change
I'm currently using the script below to change an image on rollover. There are
I have the below script to import data from a csv file on my
I have a Korn shell script that I would like to change a variable
How would I change the content of a <textarea> element with JavaScript? I want
How would I change the application identifer for a Flex app?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.