Solved Copy or repalce row in a file proj

March 5, 2018 at 05:31:37
Specs: Windows 10
hi to all, i have a problme.

i wish replace specifc row in one file (.proj)

the example is;

<Target Name="SetVersionValues" Outputs="" Condition="" DependsOnTargets="">
<!-- The regular expression ".+(?=\d{4})" means "find one or more character until the sub expression 'four consecutive digits' is matched to the right" -->
<!-- By finding everything before the 4 digits, instead of looking for "everything up to 'digit' dot 'digit' and then 'underscore' we gain more flexibility when using CruiseControl labels to do BC builds -->
<!-- This works correctly for the following style of labels from CruiseControl: GMS_1.1_BC_0058, Pawlowski_TestBuilds_0224, and GMS_1.1_0763 -->
<RegexReplace Input="$(CCNetLabel)" Expression=".+(?=\d{4})" Replacement="" Count="">
<Output ItemName="CCNetLabelRegexed" TaskParameter="Output" />
<BuildNumber>0001</BuildNumber> *****the value 0001 is the value that i want change ... with 0002 for example********

other users recommended me this solution:

::----start of test.bat----
@echo ON
set "file=output.xml"
for /f "tokens=1 delims=[]" %%a in ('type "%file%" ^| find /N "<BuildNumber>"') do set linenumber=%%a
for /f "tokens=1,2* delims=[]" %%a in ('type "%file%" ^| find /N /v ""') do if %%a LSS %linenumber% echo %%b>>output.xml
for /f "tokens=1-3 delims=<>" %%a in ('type "%file%" ^| findstr "<BuildNumber>"') do echo ^<BuildNumber^>0001^</BuildNumber^> >>output.xml
for /f "tokens=1,2* delims=[]" %%a in ('type "%file%" ^| find /N /v ""') do if %%a GTR %linenumber% echo %%b>>output.xml
::----end of test.

but the row is not overwritten, but is added to the file at the bottom

See More: Copy or repalce row in a file proj

Report •

March 5, 2018 at 20:17:39
✔ Best Answer
Ha! I thought this looked familiar:

@echo off>test2 & setlocal
set change_target=BuildNumber
set change_data=0002

for /f "tokens=*" %%a in (alej) do (
for /f "tokens=1,2 delims=<>" %%b in ("%%a") do (
if "%%b" equ "%change_target%" (
call :fix %%c
) else (
>>test2 echo %%a
rem this replaces the original file 'alej'. I left it disabled for you to compare files.
rem move test2 alej
goto :eof

>>test2 echo ^<%change_target%^>%change_data%^</change_target^>

message edited by nbrane

Report •
Related Solutions

Ask Question