necesito generar varios archivos txt que corten cuando encuentre la linea </fdaDeployJob> y darle el nombre que en este caso sería Plus_IMS_ARG_DDDLEG_002_A_20120801.ZIP
EDITO: Código mejorado
Código:
@Echo OFF
Title By Elektro H@cker
Setlocal enabledelayedexpansion
:::::::::::::::::::
Set "FILE=Test.XML"
:::::::::::::::::::
If Exist "%FILE%" (Echo Archivo a procesar: "%FILE%" | MORE) ELSE (Echo Archivo "%FILE%" no encontrado & Exit /B 1)
:: Creamos un archivo temporal y le agregamos X lineas en blanco para evitar errores en el SORT de Batch.
REM Ajustamos el número de lineas a agregar para agilizar el proceso de generación de archivos.
REM 100 lineas si el archivo original tiene menos de 100 lineas.
REM 1.000 lineas si el archivo original tiene entre 100 y 999 lineas.
REM 10.000 lineas si el archivo original tiene entre 1.000 y 9.999 lineas.
REM 100.000 lineas si el archivo original tiene entre 10.000 y 99.999 lineas.
REM 1.000.000 lineas si el archivo original tiene entre 100.000 y 999.999 lineas o más de 1.000.000 de lineas.
For /F %%a in ('Type "%FILE%" ^| find /V /C ""') do (Echo %%a>"%TEMP%\%FILE%" & FOR %%? IN ("%TEMP%\%FILE%") DO (SET /A "longitud=%%~z? - 3"))
Echo+ > "%TEMP%\%FILE%"
IF "%LONGITUD%" LEQ "2" (Set /A "LINES=100")
IF "%LONGITUD%" EQU "3" (Set /A "LINES=1000")
IF "%LONGITUD%" EQU "4" (Set /A "LINES=10000")
IF "%LONGITUD%" EQU "5" (Set /A "LINES=100000")
IF "%LONGITUD%" GEQ "6" (Set /A "LINES=1000000")
Echo Generando un archivo temporal, espere...
For /L %%X in (2,1,%LINES%) Do (Echo+ >> "%TEMP%\%FILE%")
:: Eliminamos las lineas en blanco del archivo original y copiamos el resto en el archivo temporal.
Type "%FILE%" | FINDSTR "." >> "%TEMP%\%FILE%"
:: Obtenemos los nombres de las imagenes. ("<displayName>")
For /F "Tokens=3 Delims=:<>" %%# in ('Type "%FILE%" ^| FIND /I "displayName"') do (Set /A "NUM_NAME+=1" && Set "NAME!NUM_NAME!=%%#")
:: Obtenemos el número de las lineas que contienen los delimitadores [A] y [B]. ("<fdaDeployJob" y "</fdaDeployJob>")
For /F "Delims=:" %%X in ('findstr /I /N "<fdaDeployJob " "%TEMP%\%FILE%"') do (Set /A "NUM_A+=1" && Set "Delimiter_A_!NUM_A!=%%X")
For /F "Delims=:" %%X in ('findstr /I /N "</fdaDeployJob>" "%TEMP%\%FILE%"') do (Set /A "NUM_B+=1" && Set "Delimiter_B_!NUM_B!=%%X")
:: Cortamos y generamos los archivos.
Echo+ & Echo Generando los archivos, espere... | MORE
For /L %%X in (1,1,%NUM_B%) Do (
For /F "Tokens=* Delims=:" %%@ in ('Type "%TEMP%\%FILE%"') do (
Set /A "LINE+=1"
SET "String=%%@"
IF NOT "!LINE!" GTR "!Delimiter_B_%%X!" (
IF "!LINE!" GEQ "!Delimiter_A_%%X!" (
IF NOT "!STRING!" EQU " " (
ECHO !STRING!>> "!NAME%%X!.XML"
)
)
)
)
Set /A "LIN_A=!Delimiter_A_%%X! - %LINES%", "LIN_B=!Delimiter_B_%%X! - %LINES%"
Set /A "LINE=0"
Echo [+] !NAME%%X!.XML
Echo (Linea !LIN_A! hasta Linea !LIN_B!^) | MORE
)
Echo Listo.
Pause&Exit
Output:
Plus_IMS_ARG_DDDLEG_002_A_20120801.ZIP.XML:
Código:
<fdaDeployJob xml:lang="es-ES">
<fileInfo>
<displayName>Plus_IMS_ARG_DDDLEG_002_A_20120801.ZIP</displayName>
<description>DATOS AR_DDDPLUS Argentina Ambiente plus Agosto 2012 CLIENT SERVICE, IMSHEALTH
<additionalInfo></additionalInfo>
<loginRequired>0</loginRequired>
<approved>1</approved>
<emailNotification>1</emailNotification>
<activeDate>2012/09/19</activeDate>
<expirationDate>2012/10/30</expirationDate>
<fileRule>
<productRestrictions>
</productRestrictions>
<companyRestrictions>
</companyRestrictions>
<productCompanyRestrictions>
</productCompanyRestrictions>
<individualRestrictions>
<individualEmail owner="1">aduran@ar.imshealth.com</individualEmail>
<individualEmail owner="0">mechenique@ar.imshealth.com</individualEmail>
</individualRestrictions>
<fileUploader> </fileUploader>
</fileRule>
</fileInfo>
</fdaDeployJob>
Plus_IMS_ELEKTRO_H@CKER.ZIP.XML:
Código:
<fdaDeployJob xml:lang="en-EN">
<fileInfo>
<displayName>Plus_IMS_ELEKTRO_H@CKER.ZIP</displayName>
<description>blablablabla
<additionalInfo></additionalInfo>
<loginRequired>0</loginRequired>
<approved>1</approved>
<emailNotification>1</emailNotification>
<activeDate>2011/11/22</activeDate>
<expirationDate>2011/11/22</expirationDate>
<fileRule>
<productRestrictions>
</productRestrictions>
<companyRestrictions>
</companyRestrictions>
<productCompanyRestrictions>
</productCompanyRestrictions>
<individualRestrictions>
<individualEmail owner="1">www.elhacker.net</individualEmail>
<individualEmail owner="0">Elektro H@cker</individualEmail>
</individualRestrictions>
<fileUploader> </fileUploader>
</fileRule>
</fileInfo>
</fdaDeployJob>
Y con esto cierro el tema, haz el favor de leer las normas, has revivido un tema de 2 años de antiguedad sin aportar nada, debes formular tu pregunta en un nuevo topic.
Saludos.
EDITO 2: [BATCH] [APORTE] TextCutter (Delimita texto de un archivo y lo corta en trozos)