LAKERS824
07-07-2012, 20:09
@Echo on
SetLocal EnableDelayedExpansion
Set Path=%Path%;C:\Users\Diman\Desktop\KDL\grep+parseXML\bin
Set XMLPath=C:\Users\Diman\Desktop\KDL\XML
For /F "delims=" %%F In ('Dir "%XMLPath%\*.xml" /B 2^>nul') Do (
Set Prefix=&Set InsuranceNumber=0
For /F "tokens=1,2 delims=_." %%P In ("%%~F") Do (Set Prefix=%%P&Set Suffix=%%Q)
For /F "tokens=2 delims=><" %%N In ('grep -Eo "<LastName>[^<]*</LastName>" "%XMLPath%\%%F"') Do (If Not %%N==/LastName Set LastName=%%N)
For /F "tokens=2 delims=><" %%N In ('grep -Eo "<InsuranceNumber>[^<]*</InsuranceNumber>" "%XMLPath%\%%F"') Do (
If Not %%N==/InsuranceNumber Set InsuranceNumber=%%N
)
Call :StringLen "!InsuranceNumber!"
If !$StringLen!==5 (Echo !Prefix!_!InsuranceNumber!_!LastName!|recode utf8..cp1251/>>"C:\Users\Diman\Desktop\KDL\result5and6.txt")
If !$StringLen!==6 (Echo !Prefix!_!InsuranceNumber!_!LastName!|recode utf8..cp1251/>>"C:\Users\Diman\Desktop\KDL\result5and6.txt")
If Not !$StringLen!==5 (
If Not !$StringLen!==6 (
Echo !Prefix!_!InsuranceNumber!_!LastName!|recode utf8..cp1251/>>"C:\Users\Diman\Desktop\KDL\result_other.txt"
)
)
)
Pause&Exit
:StringLen
:: Автор функции - amel27, http://forum.oszone.net/post-1162296-2.html
Set $StringLen=0&Set $StringBuf=%~1
If ""=="%~1" GoTo :EOF
:StringLenLoop
Set /A $StringLen+=1
Call Set $StringChr=%%$StringBuf:~%$StringLen%%%
If ""=="%$StringChr%" GOTO :EOF
GoTo :StringLenLoop
Запускаю с небольшой модификацией, вытаскиваю еще и Фамилию дополнительно, не более
SetLocal EnableDelayedExpansion
Set Path=%Path%;C:\Users\Diman\Desktop\KDL\grep+parseXML\bin
Set XMLPath=C:\Users\Diman\Desktop\KDL\XML
For /F "delims=" %%F In ('Dir "%XMLPath%\*.xml" /B 2^>nul') Do (
Set Prefix=&Set InsuranceNumber=0
For /F "tokens=1,2 delims=_." %%P In ("%%~F") Do (Set Prefix=%%P&Set Suffix=%%Q)
For /F "tokens=2 delims=><" %%N In ('grep -Eo "<LastName>[^<]*</LastName>" "%XMLPath%\%%F"') Do (If Not %%N==/LastName Set LastName=%%N)
For /F "tokens=2 delims=><" %%N In ('grep -Eo "<InsuranceNumber>[^<]*</InsuranceNumber>" "%XMLPath%\%%F"') Do (
If Not %%N==/InsuranceNumber Set InsuranceNumber=%%N
)
Call :StringLen "!InsuranceNumber!"
If !$StringLen!==5 (Echo !Prefix!_!InsuranceNumber!_!LastName!|recode utf8..cp1251/>>"C:\Users\Diman\Desktop\KDL\result5and6.txt")
If !$StringLen!==6 (Echo !Prefix!_!InsuranceNumber!_!LastName!|recode utf8..cp1251/>>"C:\Users\Diman\Desktop\KDL\result5and6.txt")
If Not !$StringLen!==5 (
If Not !$StringLen!==6 (
Echo !Prefix!_!InsuranceNumber!_!LastName!|recode utf8..cp1251/>>"C:\Users\Diman\Desktop\KDL\result_other.txt"
)
)
)
Pause&Exit
:StringLen
:: Автор функции - amel27, http://forum.oszone.net/post-1162296-2.html
Set $StringLen=0&Set $StringBuf=%~1
If ""=="%~1" GoTo :EOF
:StringLenLoop
Set /A $StringLen+=1
Call Set $StringChr=%%$StringBuf:~%$StringLen%%%
If ""=="%$StringChr%" GOTO :EOF
GoTo :StringLenLoop
Запускаю с небольшой модификацией, вытаскиваю еще и Фамилию дополнительно, не более