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 6607205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:28:42+00:00 2026-05-25T19:28:42+00:00

Trying to replace a string in a properties file on a certain line by

  • 0

Trying to replace a string in a properties file on a certain line by using a batch file. I know that this can be done WITHOUT the use of a temp file, as I have seen it before, but forgotten how to do it.

I know that if I have a var.properties file that contains this:

CLASSPATH=bsh.jar;other.jar
VARTEST=dummy
ANOTHERVAR=default

I am trying to update the CLASSPATH value in the .properties file without changing the order of the properties file.

This is a properties file and so I believe the answer would be related to using:

for /f "tokens=1,2* delims==" %%i in (var.properties) do (
  @echo Key=%%i Val=%%j
)
  • 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-25T19:28:43+00:00Added an answer on May 25, 2026 at 7:28 pm

    I finally broke down and accepted a method using a “temp” file. Using delayed expansion with the ‘!’ character solved my question. Much of this success was due to input by mecaflash .

    You can call this script with: CALL Script.bat PropKey NewPropValue Filename

    @echo off
    :: script for updating property files
    SETLOCAL EnableExtensions
    SETLOCAL EnableDelayedExpansion
    if "%3"=="" (
      ECHO Script will optionally accept 3 args: PropKey PropVal File
      SET PROPKEY=UseCompression
      SET PROPVAL=false
      SET FILE=config.properties
    ) ELSE (
      SET PROPKEY=%1
      SET PROPVAL=%2
      SET FILE=%3
    )
    FINDSTR /B %PROPKEY% %FILE% >nul
    IF %ERRORLEVEL% EQU 1 GOTO nowork
    MOVE /Y "%FILE%" "%FILE%.bak"
    FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
      SET LINE=%%A
    )
    FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
    SET /A LINE=%LINE:~1,6%
    SET /A COUNT=1
    FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
      IF "!COUNT!" NEQ "%LINE%" (
          ECHO %%A>>"%FILE%"
      ) ELSE (
          ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
          ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
      )
      SET /A COUNT+=1
    )
    GOTO end
    :nowork
    echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
    pause
    :end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the .NET framework, I'm trying to replace double slash characters in a string
I'm trying to replace each , in the current file by a new line:
I trying to replace string Resources.AppResource.Info; like this Switch(Info); Is this possible with regex?
I am trying to read the XML Documentation file (C#) using this ocde -
I am trying to insensitive replace string, so I'm using str_ireplace() but it does
I've been trying to replace to following string using the following... var r =
I am trying to replace all $ characters in a String expression like this
I am trying to replace/modify a part of string in a python file from
i'm trying to replace the string location to tocation so basically this is my
I'm trying to replace a string in an xml file with python. For example:

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.