I have text file which is fixed width. I need to delimit the contents based upon the Column number ( Column 100-120 ) into a variable and need to check length of the variable.
There are chance that variable has more than 20 character and i need to remove that particular line
Eg :
0 1 2 3 4 5 6 7 8 9 0
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
short_name des_shrt px
BOS1111 ALTIC 6.62 2_23 106.37500000
BOS2222 AMA 47.26000000
BOS3333 AMB 12.898000
BOS4444 AMEX Express 10.09780000
BOS5555 BBC 111.2233
BOS6666 CNN 123.123445
BOS7777 STACK OVERFLOW 344.9090
BOS8888 STACT 12.0 2/1988 10.99999999
BOS9999 ABC 20
Output :
px
106.375
47.26
12.898
10.0978
111.2233
123.123445
344.909
10.99999999 -> it exceeds 10 digit and should throw error
20
Here is a pure batch-file solution – see all the explanatory remarks in the code:
#echo off
setlocal EnableDelayedExpansion
rem // Define constants here:
set "_FULL_LINES_OUT=#"
rem // Initialise variables:
set "HEAD=#"
rem // Read text file line by line:
for /F "usebackq delims=" %%L in ("%~1") do (
rem // Store current line into environment variable:
set "LINE=%%L"
rem // Extract 12 characters at character position 58:
set "LINE=!LINE:~58,12!"
rem // Remove trailing spaces, if any:
for /F %%K in ("!LINE!") do set "LINE=%%K"
rem // Check whether line is the first one (header):
if defined HEAD (
rem // Return header line:
if defined _FULL_LINES_OUT (echo %%L) else (echo !LINE!)
set "HEAD="
) else (
rem // Split numbers into integer and fractional parts:
for /F "tokens=1* delims=." %%I in ("!LINE!") do (
set "INT=%%I" & set "FRACT=%%J"
)
rem // Remove trailing zeros from fractional part:
set "FLAG=#"
for /L %%J in (1,1,12) do (
if defined FLAG (
if "!FRACT:~-1!"=="0" (
set "FRACT=!FRACT:~,-1!"
) else (
set "FLAG="
)
)
)
rem // Reassemble truncated decimal number:
if defined FRACT (
set "LINE=!INT!.!FRACT!"
) else (
set "LINE=!INT!"
)
rem // Check whether string length of number exceeds 10:
if not "!LINE:~10!"=="" (
rem // Number is longer than 10 characters:
>&2 (if defined _FULL_LINES_OUT (echo %%L) else (echo !LINE!))
) else (
rem // Number is not too long, so return original line:
if defined _FULL_LINES_OUT (echo %%L) else (echo !LINE!)
)
)
)
endlocal
exit /B
Supposing you name the script check-px-numbers.bat and your data file is called D:\Data\data.txt, run the script like this:
check-px-numbers.bat "D:\Data\data.txt" 2> nul
To write the output into another file D:\Data\filtered.txt, call the script like this:
check-px-numbers.bat "D:\Data\data.txt" > "D:\Data\filtered.txt"
This would return the following output file when using your sample data:
short_name des_shrt px
BOS1111 ALTIC 6.62 2_23 106.37500000
BOS2222 AMA 47.26000000
BOS3333 AMB 12.898000
BOS4444 AMEX Express 10.09780000
BOS5555 BBC 111.2233
BOS6666 CNN 123.123445
BOS7777 STACK OVERFLOW 344.9090
BOS9999 ABC 20
And the following error message would appear in the console window:
BOS8888 STACT 12.0 2/1988 10.99999999
Change the line set "_FULL_LINES_OUT=#" to set "_FULL_LINES_OUT=" (or remove it) if you want your output data to look like this:
px
106.375
47.26
12.898
10.0978
111.2233
123.123445
344.909
20
In case you want to overwrite the original file, you need to do that in two steps:
check-px-numbers.bat "D:\Data\data.txt" > "D:\Data\filtered.txt"
> nul move /Y "D:\Data\filtered.txt" "D:\Data\data.txt"
To write the erroneous lines into a file, use this:
check-px-numbers.bat "D:\Data\data.txt" 2> "D:\Data\errors.txt"
You can combine this to write the filtered and the error lines at once like this:
check-px-numbers.bat "D:\Data\data.txt" > "D:\Data\filtered.txt" 2> "D:\Data\errors.txt"
Related
how please can I 'pivot' or transpose a file (i.e. turn a single-column list, into a table of data)...
Currently...
VideoA.name
VideoA.size
VideoA.bitrate
VideoB.name
VideoB.size
VideoB.bitrate
...
Desired...
VideoA.name, VideoA.size, VideoA.bitrate
VideoB.name, VideoB.size, VideoB.bitrate
Name
Size
Bitrate
VideoA.name
VideoA.size
VideoA.bitrate
VideoB.name
VideoB.size
VideoB.bitrate
Extra Info / Context
I'm aware people often ask 'why are you doing this?' so (if interested), here is the wider context / problem I am trying to solve...
I have a list of files in Files.txt
I have a jscript batch file getProps.bat that extract file properties and prints them, 1 per line
I have written a batch file to loop through Files.txt, get the properties of each and write the output to Details.csv
However if I have 500 files x 3 properties, this currently gives me 1500 lines, and I want 500 lines x 3 columns
GetProps_AllFiles.bat
---------------------
#ECHO OFF
SETLOCAL
FOR /F "tokens=*" %%A in (Files.txt) do (
getprops %%A 0,1,320 /noheaders >> Details.csv
)
Thanks in advance!
Use the "standard way" (for /f) to read a file line by line, extended by a counter. Add the line to a string (line), followed by a comma (or whatever you want to use as separator), and increase the counter. Except it's the third line. Then print the string plus the current line, reset the counter and string, and repeat.
#echo off
setlocal enabledelayedexpansion
set "line="
set count=0
(for /f "delims=" %%a in (test.txt) do (
set /a count+=1
if !count! equ 3 (
echo !line!%%a
set "line="
set count=0
) else (
set line=!line!%%a,
)
))>test.csv
The below is a slight adjustment to the code kindly provided by Stephan that allows a filename and number of lines to be passed into the script...
ColumiseFile.cmd
----------------
#ECHO OFF
SETLOCAL enabledelayedexpansion
REM :: USAGE -----------------------------------------------------------------
REM ColumiseFile [1]File.txt [2]NumOfLines
REM > Concatenates every n Lines into 1, exporting result to File.csv
SET "File=%1"
SET /A Lines=%2
REM :: MAIN -------------------------------------------------------------------
REM Thanks to Stephan [https://stackoverflow.com/a/67664755/15919675]
REM Loops through input file, compacting every n lines into 1
set "line="
set count=0
(for /f "delims=" %%a in (%File%) do (
set /a count+=1
if !count! equ %Lines% (
echo !line!%%a
set "line="
set count=0
) else (
set line=!line!%%a,
)
REM :: OUTPUT -----------------------------------------------------------------
REM Create .csv in same location as source .txt file
))>%~dpn1.csv
I want to insert a string of text say "hello" in a particular line say n (12 or 23 or some other number) using batch script. I know batch script is bad but unfortunately the requirement for this is batch script.
Here's what I've tried
#echo off
setlocal enableextensions disabledelayedexpansion
set "nthline=TEXT"
(for /f "usebackq tokens=* delims=" %%a in (c.txt) do (
echo(%%a
if defined nthline (
echo(%nthline%
set "nthline="
)
))
This code I got from here but it only inserts to the second line I cannot make it go beyond that.
Here is what the text file contains
aaaa
bbbb
cccc
dddd
ffff
gggg
hhhh
It inserts the string after aaaa. How can I make it insert at bbbb or ffff I'm new to batch scripting so Any help is greatly appreciated
The code you have posted is designed to insert an extra line after the first one.
To insert at a certain point you need to somehow predefine the target line number and a line number, then compare these numbers for equality and return the extra line of text ‐ line in the following script:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constante here:
set "_FILE=c.txt" & rem // (text file to insert a line of text into)
set "_TEXT=hello" & rem // (text of the inserted line)
set /A "_NUM=4" & rem // (number of the line where the new line is inserted)
set "_REPLAC=#" & rem // (set to anything to replace the target line, or to nothing to keep it)
set "_TMPF=%TEMP%\%~n0_%RANDOM%.tmp" & rem // (path and name of temporary file)
rem // Write result into temporary file:
> "%_TMPF%" (
rem // Loop through all lines of the text file, each with a preceding line number:
for /F "delims=" %%L in ('findstr /N "^" "%_FILE%"') do (
rem // Store current line including preceding line number to a variable:
set "LINE=%%L"
rem // Set the current line number to another variable:
set /A "LNUM=%%L"
rem // Toggle delayed expansion to avoid trouble with `!`:
setlocal EnableDelayedExpansion
rem // Compare current line number with predefined one:
if !LMUN! equ %_NUM% (
rem // Line numbers match, so return extra line of text:
echo(!_TEXT!
rem // Return original line (without preceding line number) only if it is not to be replaced:
if not defined _REPLAC echo(!LINE:*:=!
) else (
rem // Line numbers do not match, so return original line (without preceding line number) anyway:
echo(!LINE:*:=!
)
endlocal
)
)
rem // Move temporary file onto original one:
move /Y "%_TMPF%" "%_FILE%"
endlocal
exit /B
Is there any command to know the encoding of a file in windows?
like for a file A.txt encoding is UTF-16
In Windows command prompt (cmd), there is no command I know of, that is capable of determining how a text file is encoded.
Nevertheless, I wrote a small batch file that is able to check a few conditions and thus, determine whether a given text file is ASCII-/ANSI-encoded or Unicode-encoded (UTF-8 or UTF-16, Little Endian or Big Endian). At first, it checks whether or not the first (non-empty) line contains zero-bytes, which is an indication that the file is not ASCII-/ANSI-encoded. Next, it checks the first few bytes whether they constitute the Byte Order Mark (BOM) for UTF-8/UTF-16. Since the BOM is optional for Unicode-encoded files, its absence is not a clear sign for an ASCI-/ANSI-encoded file.
So here is the code, featuring a lot of explanatory remarks (rem) -- I hope, it helps:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_FILE=%~1" & rem // (provide file via the first command line argument)
rem // Check whether a dedicated file is given (so no wild-cards):
2> nul >&2 (< "%_FILE%" set /P ="" & ver) || (
rem // The file does not exist:
>&2 echo The file could not be found, hence there is no encoding!
exit /B 255
)
rem // Determine the file size:
set "SIZE=" & for %%F in ("%_FILE%") do set "SIZE=%%~zF"
if not defined SIZE (
rem // The file does not exist:
>&2 echo The file could not be found, hence there is no encoding!
exit /B 255
)
if %SIZE% EQU 0 (
rem // The file is empty:
>&2 echo The file is empty, hence encoding cannot be determined!
exit /B 1
)
rem // Store current code page to be able to restore it finally:
for /F "tokens=2 delims=:" %%C in ('chcp') do set /A "$CP=%%C"
rem /* Change to code page 437 (original IBM PC or DOS code page) temporarily;
rem this is necessary for extended characters not to be converted: */
> nul chcp 437
rem // Attempt to read first line from file; this fails if zero-bytes occur:
(
rem /* The loop does not iterate over an empty file or one with empty lines only;
rem therefore, the behaviour is the same as when zero-bytes occur: */
for /F usebackq^ delims^=^ eol^= %%L in ("%_FILE%") do (
rem // Abort reading file after first non-empty line:
goto :NEXT
)
) || (
rem /* The `for /F` loop returns a non-zero exit code in case the file is empty,
rem contains empty lines only or the first non-empty line contains zero-bytes;
rem to determine whether there are zero-bytes, let `find` process the file,
rem which removes zero-bytes or converts them to line-breaks, so `for /F` can
rem read the file;
rem however, `find` would read the whole file, hence do that only for small
rem ones and skip that for large ones, such contains zero-bytes most likely: */
if %SIZE% LEQ 8192 (
(
rem // In case the file contains line-breaks only, the loop does not iterate:
for /F delims^=^ eol^= %%L in ('^< "%_FILE%" find /V ""') do (
rem // Abort reading file after first non-empty line:
goto :ZERO
)
) || (
rem /* The loop did not iterate, so the file contains line-breaks only;
rem restore the initial code page prior to termination: */
> nul chcp %$CP%
>&2 echo The file holds only empty lines, hence encoding cannot be determined!
exit /B 1
)
)
)
rem // This point is reached in case the file contains zero-bytes:
:ZERO
rem // Restore the initial code page prior to termination:
> nul chcp %$CP%
>&2 echo NULL-bytes detected in first line, so file is non-ASCII/ANSI!
exit /B 2
rem // This point is reached in case the file does not contain any zero-bytes:
:NEXT
rem /* Build Byte Order Marks (BOMs) for UTF-16-encoded text (Little Endian and Big Endian)
rem and for UTF-8-encoded text: */
for /F "tokens=1-3" %%A in ('
forfiles /P "%~dp0." /M "%~nx0" /C "cmd /C echo 0xFF0xFE 0xFE0xFF 0xEF0xBB0xBF"
') do set "$LE=%%A" & set "$BE=%%B" & set "$U8=%%C"
rem /* Reset line string variable, then store first line string (1023 bytes at most);
rem in contrast to `for /F`, this does not skip over blank lines: */
< "%_FILE%" (set "LINE=" & set /P LINE="")
rem // Check whether the first line of the file begins with any of the BOMs:
if not "%LINE:~,2%"=="%$LE%" if not "%LINE:~,2%"=="%$BE%" if not "%LINE:~,3%"=="%$U8%" goto :CONT
rem /* One of the BOMs has been encountered, hence the file is Unicode-encoded;
rem restore the initial code page prior to termination: */
> nul chcp %$CP%
>&2 echo BOM encountered in first line, so file is non-ASCII/ANSI!
exit /B 4
rem // This point is reached in case the file does not appear as Unicode-encoded:
:CONT
rem // Restore the initial code page prior to termination:
> nul chcp %$CP%
echo The file appears to be an ASCII-/ANSI-encoded text.
endlocal
exit /B 0
I want to create a batch file on Windows that can let the user enter only a number between 1-31... I could use this number later in the batch file... It is possible ?
I tried this
set /P "month=Enter the month of the year : "
findstr /i %month% %file% | sort /+24
Thanks :)
#echo off
:try_again
set /P "month=Enter the month of the year : "
echo %month%|findstr /r "[^0-9]" && (
echo enter a number
goto :try_again
)
::clears the leading zeroes.
cmd /c exit /b %month%
set /a month=%errorlevel%
if %month% gtr 31 (
echo enter a number between 1 and 31
goto :try_again
)
if %month% lss 1 (
echo enter a number between 1 and 31
goto :try_again
)
?
Well, these two options are entirely different:
Let the user enter anything; then, check if the input is a number between 1 and 12 and retry the input if it is not.
Let the user just enter a number between 1 and 12.
The Batch file below implement the second method:
#echo off
setlocal EnableDelayedExpansion
echo Precede numbers 1 and 2 by a zero
set /P "=Enter a month: " < NUL
choice /C 0123456789 > NUL
set /A "number=%errorlevel%-1"
if %number% gtr 1 echo %number% & goto continue
set /P "=%number%" < NUL
if %number% equ 0 (
choice /C 12 > NUL
set "digit2=!errorlevel!"
) else (
choice /C 012 > NUL
set /A "digit2=!errorlevel!-1"
)
echo %digit2%
set /A "number=number*10+digit2"
:continue
echo/
echo Number read: %number%
A very simple but efficient method I use when I need a non-zero numeric input is the following code (note that this verifies the user entry afterwards):
:RETRY_RESET
rem /* Since zero is considered as invalid, preset variable to `0` to
rem not keep the former value in case the user just presses ENTER;
rem you could also define a non-zero default value here optionally: */
set /A NUMBER=0
:RETRY_REUSE
rem // Display prompt now:
set /P NUMBER="Please enter a positive number: "
rem /* Convert entry to a numeric value; everything up to the first
rem numeral is converted to a numeric value, except leading SPACEs
rem or TABs are ignored and signs `+` and `-` are recognised: */
set /A NUMBER+=0
rem /* Caution: numbers with leading `0` are converted to octal ones!
rem since `8` and `9` are not valid octal numerals, entries with
rem such figures and leading zeros are converted to `0`! */
rem // Verify entry:
if %NUMBER% EQU 0 goto :RETRY_RESET
rem // Do something with `%NUMBER%` at this point...
rem /* Afterwards you can jump to `:RETRY_RESET` to enter another number;
rem alternatively, jump to `:RETRY_REUSE` to maintain the former entry
rem in case the user just presses ENTER... */
This will not fail for any entry you can think of because the variable NUMBER holding the value is never expanded before it is converted to a true number by set /A NUMBER+=0.
The script recognises + and - signs correctly. Leading white-spaces are ignored. Besides all those, everything up to the first non-numeric figure is converted to a number; so for instance, an entry like SPACE+15.75k is converted to 15 as the . is not a numeral.
The disadvantage of this approach is that leading zeros may lead to unexpected results as set /A interpretes numbers with such as octal ones; so for instance, 012 is converted to (decimal) 10, and 08 and 09 are converted to 0 as 8 and 9 are not valid octal digits.
A good point though could be the fact that hexadecimal numbers are recognised correctly in case they are prefixed with 0x; for example, 0x18 is converted to 24; 0xAS becomes 10 (as S is not hex.).
A safe and simple manner for performing this task is the use of the Set /A command in conjunction with the || conditional operator and a :label to return to for when invalid input is entered.
A number of tests can be performed on the input value using set /a without expanding the variables content in a manner that leaves your code vulnerable to code injection.
An example:
#Echo off
Call:ValidNum $RV 31
Call:ValidNum "" "" 5
Set $
Goto:Eof
:ValidNum [returnvar] [max] [min]
SETLOCAL
Set "sign=-1"
:VNumIn
%= ensure nul value =%
Set "input="
%= define max value =%
2> nul Set /a "max=%~2" || Set "max=2147483647"
%= define min value =%
2> nul Set /a "min=%~3" || Set "min=1"
Set /p "input=Enter a number GEQ %min% LEQ %max%: "
%= Input Testing. input +/- , input > min , input < max , Hex/Octal for comparison =%
2>nul Set /a "1/(sign-(input>>31))","max/(input/min)","1/(max/input)","HexOct=input" || Goto:VNumIn
%= compare assignments to block hex, octal and leading 0's =%
If not "%Input%"=="%HexOct%" Goto:VNumIn
( %= return value in $Num if no arg 1, else return in Arg1 =%
ENDLOCAL & Set "%~1=%input%" 2> nul || Set "$Num=%input%"
Goto:Eof
)
The following script is sort of a mixture of both restricting characters/key during entry and verifying characters/value after entry. The code is quite complex but it is very flexible and also safe. Here is it:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here (`findstr` reg. expr.):
set "WHITE=[0-9]" & rem // (positive list, accepted characters)
set "BLACK=[^`^]" & rem // (negative list, rejected characters)
set "LENGTH=2" & rem // (optional limit for length of entry)
rem // resolve length limit:
set /A LENGTH-=1
if %LENGTH% LSS 0 set "LENGTH="
rem // Retrieve back-space character:
for /F %%C in ('echo prompt $H ^| cmd') do set "BS=%%C"
:HOOK
rem // Display prompt:
echo(Please enter something:
set "ENTRY="
:LOOP
rem // Use `xcopy /W` to capture a single key stroke:
set "KEY="
for /F "delims=" %%K in ('2^> nul xcopy /L /W "%~f0" "%~f0"') do (
if not defined KEY set "KEY=%%K"
)
set "KEY=%KEY:~-1%"
rem // Leave loop in case ENTER has been pressed:
if not defined KEY goto :NEXT
rem // Disallow `"` to avoid syntax errors (`if`, no del. exp.):
set "KEY=%KEY:"=%" & rem "
rem // Disallow `=` to avoid syntax errors (`set /P`):
if "%KEY%"=="=" set "KEY="
rem // Disallow ` ` (tabulator):
if "%KEY%"==" " set "KEY="
rem // Optional additional filter (include):
if defined WHITE (
(echo("%KEY%" | > nul findstr /R /C:"%BS%" /C:"%WHITE%") || (
set "KEY="
)
)
rem // Optional additional filter (exclude):
if defined BLACK (
(echo("%KEY%" | > nul findstr /R /C:^"\"%BLACK%\"^") || (
set "KEY="
)
)
rem // In general, display string equals pressed key:
set "DISPLAY=%KEY%"
rem // Avoid space in display text (ignored by `set /P`):
if "%KEY%"==" " set "DISPLAY=_%BS% "
rem // Force to clear preceding character upon back-space:
if "%KEY%"=="%BS%" (
set "DISPLAY=%BS% %BS%"
if defined ENTRY set "ENTRY=%ENTRY:~,-1%"
set "KEY="
)
rem // Ignore any more character if length limit is reached:
set "TEST=%ENTRY%"
if defined LENGTH if defined ENTRY (
call set "TEST=%%ENTRY:~,%LENGTH%%%"
)
if not "%TEST%"=="%ENTRY%" (
set "KEY=" & set "DISPLAY="
)
set "ENTRY=%ENTRY%%KEY%"
rem // Show display text:
< nul set /P ="%DISPLAY%"
goto :LOOP
:NEXT
echo(
rem /* Verify the entry; for instance,
rem check numeric value after removal of leading zeros: */
cmd /C exit %ENTRY%
set /A ENTRY=%ErrorLevel%
set /A ENTRY+=0 & rem // (conversion to true numeric value)
if %ENTRY% LEQ 0 goto :HOOK
if %ENTRY% GTR 12 goto :HOOK
rem // Do something with the entry (display):
echo(You entered this value:
< nul set /P ="%ENTRY%"
echo(
endlocal
exit /B
The core of the script is the xcopy /L /W command which takes a single key stroke (/W) and does no copying (/L). Its output is captured by a for /F loop to get the current key or character. For displaying < nul set /P is used with nothing sent into its prompt but the message text displayed, which is not terminated by a line-break unlike echo. Consult also the comments (rem) in the code.
The script can be configured in the Define constants here block at the top:
variable WHITE defines a positive character set for the findstr command, one of which a character/key must equal; set to an empty string to disable this set; for our situation, [0-9] is suitable as it defines to accept only numeric figures;
variable BLACK defines a negative character set for the findstr command, one of which a character/key must not equal; set to an empty string to disable this list; since there is already WHITE defined, BLACK is not needed; the first character within the brackets [ ] must be a caret ^ so that the given characters are truly rejected; if the sets in WHITE and BLACK overlap, the latter takes precedence;
variable LENGTH defines the greatest length of the entry, so if the given number of characters have been supplied, no more are accepted; you can delete the last character though by the ←— key; since we need a two-digit numeric value, 2 is the value of choice here;
I need to parse a file that has the following format:
A + tags/RWSTestConsole_tag1/
(from trunk/RWSTestConsole/:r776)
So I'm using a FOR /F loop with a counter and inspecting the tokens based on whether I'm looking at line 1 or line 2. Everything works fine except the first token for line 2 includes the leading spaces (" from") and a) I thought the delims on my FOR would take care of spaces and b) theoretically I could just compare to a constant string that is set to " from" but that's kind of hokey.
This is my FOR command:
for /F "tokens=1,2,3,4,5 delims=():/ " %%a in (svn.txt) DO (
Is there a change I can make to the FOR command to ignore the spaces? If not is there a way to trim the token inside the FOR loop's DO clause so I only get the word without the leading spaces?
Edit:
This is output from a Subversion SVNLOOK command in a script that is managing whether or not to allow a "tag" to be created. The output can be 1 line that must be formatted as:
D /tags/tagfoldername/
If it's one line but it's not a delete for the actual tag folder then it's an error. This case is handled.
If it's more than 2 lines it's a list of files and that's an error. I have that handled.
The case I'm having problems with is if it is 2 lines it needs to be in the format shown above:
A + tags/RWSTestConsole_tag1/
(from trunk/RWSTestConsole/:r776)
Where col 1 = "A". col 3 = "+", col 5 = "tags" and the remainder of line one is the tag folder name. The second line is the source of the create request so it has to start with "from", followed by "trunk", "branches" or "tags" followed by a single-level folder name and a revision number.
I used the FOR command as described above. In the DO clause I look at a counter to tell if I'm parsing line 1 or line 2. Line 1 is simple, I have all the logic to handle it.
Line 2 is parsed by the same FOR command and the first token (%%a) removes the "{" from delims, but leaves behind all the leading blanks so I get back %%a=" from".
I need to know if there's a way I can modify the FOR command to remove the blanks or a way to trim %%a within the FOR DO clause to remove the blanks.
Edit 2: FOR Loop Code
set c=1
for /F "tokens=1,2,3,4,5 delims=():/ " %%a in (svn.txt) DO (
echo op=%%a, %%b, %%c, %%d, %%e
if !c!==1 (
set rc1=0
if /I %%a EQU A (
if "%%b" EQU "+" (
if [%%e] EQU [] (
echo Tag from a Copy Op
set rc1=0
) else (
echo Found a subfolder: %%e - not a tag delete
set rc1=1
)
) else (
echo Tag not a Copy
set rc1=1
)
)
)
if !c!==2 (
set rc2=0
set str1=%%a
echo String replace 1 = !str!
set str2=!str1:~-4!
echo String Replace 2 *!str2!*
if /I !str2! EQU FROM (
set isvalid=false
if %%b EQU trunk set isvalid=true
if %%b EQU branches set isvalid=true
if %%b EQU tags set isvalid=true
if !isvalid! EQU true (
set rc2=0
) else (
set rc2=1
echo Invalid source for Tag Creation
)
) else (
set rc2=1
echo Tag not FROM
)
)
set /a c+=1
)
echo RC1=!rc1!
echo RC2=!rc2!
set /a rc=!rc1!+!rc2!
echo final RC = !rc!