O próximo trecho de código comentado deve fazer o trabalho:
@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
rem delete auxiliary variables
for /F %%G in ('set ___ 2^>NUL') do set "%%G="
rem count up number of occurrences
for /F tokens^=2^ delims^=^" %%G in ('
FINDSTR /C:"Widget Name=" "configure.txt"
') do set /A "___%%G+=1"
rem subtract 1 to get number of duplicates
for /F "tokens=1,2 delims==" %%G in ('set ___ 2^>NUL') do set /A "%%G-=1"
REM output: does dot work if your data contains _ underscore
REM for /F "tokens=1,2 delims=_=" %%G in ('set ___ 2^>NUL') do echo %%G %%H
rem alternative output
for /F "tokens=1,2 delims==" %%G in ('set ___ 2^>NUL') do (
set "_auxvarname=%%G"
call set "_auxvarname=%%_auxvarname:~3%%"
SETLOCAL EnableDelayedExpansion
echo !_auxvarname! %%H
ENDLOCAL
)
Para criar o arquivo de saída, altere as últimas linhas da seguinte forma:
rem alternative output
> output.txt (
for /F "tokens=1,2 delims==" %%G in ('set ___ 2^>NUL') do (
set "_auxvarname=%%G"
call set "_auxvarname=%%_auxvarname:~3%%"
SETLOCAL EnableDelayedExpansion
echo !_auxvarname! %%H
ENDLOCAL
)
)
Saída com dados mesclados da pergunta original e de atualizados um:
==> type "configure.txt"
<Widget Name="example1"/>
<Property Name="exmaple2"/>
<Content Name="example3"/>
<Widget Name="example4"/>
<Widget Name="example1"/>
<Widget Name="example_1_new" Type="IFC"/>
<Property Name="exmaple_2_old"/>
<Content>
<Widget Name="example_3_new"/>
<Widget Name="example_4_old"/>
<Widget Name="exmaple_1_new"/>
</Content>
==> D:\bat\SU94786.bat
example1 1
example4 0
example_1_new 0
example_3_new 0
example_4_old 0
exmaple_1_new 0