0

How can i search for "description=" if exists do nothing but if it doesn't exists add a under version line using batch script.

package.xml

<?xml version="1.0" encoding="utf-8"?>
<PackageManifest>
  <Package name="audio"
           version="1.37.0"
           description="something.  . .."
           comment="">
   </Package>
</PackageManifest>

1 Answer 1

1
@ECHO OFF
SETLOCAL
DEL newfile.txt 2>nul
SET "description=replacement text"
SET "inserted="
SET "version="
FINDSTR /L /c:"description=" q25186276.txt >NUL
IF ERRORLEVEL 1 (
 FOR /f "delims=" %%a IN (q25186276.txt) DO (
  ECHO(%%a
  FOR /f "tokens=1*delims== " %%b IN ("%%a") DO (
   IF "%%b"=="version" ECHO(     description="%description%"
  )
 )
)>newfile.txt
IF EXIST newfile.txt move /y newfile.txt q25186276.txt >NUL 2>nul

GOTO :EOF

I used a file named q25186276.txt containing your data for my testing.

You would need to set the description and indent-spacing to suit.

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

1 Comment

Thank you very much for your help.. lifesaver :)

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.