0

I am working to install a product on my windows 7 system, i need to search for a line in a text file, inside the component folder by name IRU_install.properties there i have to search for a line licenseType=LICR and need to append a line "licenseAccepted=9" after the line is found in the properties file.I do not want to prompt the user as the installation need to be through Batch script and silent installation process.

1
  • for /f Should be pretty easy. Commented Jul 8, 2016 at 13:14

1 Answer 1

1

You can use the findstr command to find text within a file. See below for an example:

findstr /m "licenseType=LICR" IRU_INSTALL.properties
if %errorlevel%==0 (
echo Line found!
)

This finds the string specified in the file specified. The /m switch tells the command to print the filename ONLY if there is a match. use findstr /? to learn more.

As for appending text, this can be super difficult in Batch, but it can be done.

See the below code:

@ECHO OFF
(
  FOR /F "tokens=*" %%A IN (IRU_install.properties) DO (
    ECHO %%A
    IF "%%A" EQU "licenseType=LICR" (
      ECHO licenseAccepted=9
    )
  )
) >output.txt
move /y output.txt IRU_install.properties

What this does is it uses the FOR command to iterate through the lines in the file and if the current line equals the wanted line, then output the license accepted line to a 'output.txt' file. Then move all the text in that to the .properties file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.