How to concat new line character in windows batch script - windows

I have the following code
#echo off
setlocal enableextensions disabledelayedexpansion
set "search=hello"
set "replace=hello world"
set "textFile=hello.text"
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%textFile%" echo(!line:%search%=%replace%!
endlocal
)
How can I add new line character between Hello and world using this script
My hello.txt contains the following:
def a=1
config{
hello
}
I want to change into
def a=1
config{
hello
world
}
The main aim is to add world after hello in the next line

By modifying the replacement string you could achieve what you want:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "search=hello"
rem // In the following, the empty lines are intentional; ensure that there are not even (trailing) spaces!
set replace=hello^^^
^
world
set "textFile=hello.txt"
for /F "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
setlocal EnableDelayedExpansion
>>"%textFile%" echo(!line:%search%=%replace%!
endlocal
)
endlocal
exit /B
With the sequence ^^^ + line-break + line-break + ^ + line-break + line-break you build a double-escaped line-break, which will result in the string ^ + line-break + line-break to be assigned to the variable replace. This is going to expand to a single line-break during expansion of the expression %replace%.
The aforementioned script unfortunately uses a line-feed character only as the line-break in the replacement string instead of carriage-return plus line-feed as would be Windows-conform. To overcome that issue, the following script may be used instead:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define a line-break (carriage-return plus line-feed):
for /F %%l in ('copy /Z "%~f0" nul') do (set ^"nl=%%l^
%=empty line =%
^")
set "search=hello"
rem // Use defined line-break variable here (it will not yet be expanded here):
set "replace=hello!nl! world"
set "textFile=hello.txt"
setlocal EnableDelayedExpansion
rem // At this point the line-break variable is going to be expanded:
for %%j in ("%replace%") do (
rem /* Use `findstr /N` rather than `type` to precede every line with
rem line number plus `:` to avoid loss of empty lines due to `for /F`: */
for /F "delims=" %%i in ('findstr /N "^^" "!textFile!" ^& break ^> "!textFile!"') do (
endlocal & set "line=%%i" & setlocal EnableDelayedExpansion
rem // Remove line number prefix:
set "line=!LINE:*:=!"
rem // Actually perform sub-string replacement:
>>"!textFile!" echo(!line:%search%=%%~j!
)
)
endlocal
endlocal
exit /B
This approach also maintains blank lines in the text file.

Related

Creating Each line of text as variable and them constantly changing in a loop in batch

So what I'm trying to do is create a find for multiple people where it in the text file it will say names and numbers like
Example of text file:
Beth
1234567891
Jay
2134456544
This is the best way I can explain what I'm trying to do:
#echo off
set "file=Test1.txt"
setlocal EnableDelayedExpansion
<"!file!" (
for /f %%i in ('type "!file!" ^| find /c /v ""') do set /a n=%%i && for /l %%j in (1 1 %%i) do (
set /p "line_%%j="
)
)
set /a Name=1
set /a Number=2
Echo Line_%Name%> %Name%.txt (Im trying to get this to say line_2 to say 1st line in the text file)
Echo Line_%Number%> %Name%.txt (Im trying to get this to say line_2 to say 2nd line in the text file)
:Start
set /a Name=%Name%+2 (These are meant to take off after 1 so lines 3,5,7,9 so on)
set /a Number=%Number%+2 (These are meant to take off after 2 so lines 4,6,8,10 so on)
Echo Line_%Name%
Echo Line_%Number%
GOTO :Start
so the outcome would be
In Beth.txt:
Beth
1234567891
So every name will be a file name and the first line in a file. I will change it later so I can do a addition in each text file.
Name: Beth
Number: 1234567891
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=u:\your files"
SET "destdir=u:\your results"
SET "filename1=%sourcedir%\q65417881.txt"
rem make sure arrays are empty
For %%b IN (name number) DO FOR /F "delims==" %%a In ('set %%b[ 2^>Nul') DO SET "%%a="
rem Initialise counter and entry array
SET /a count=0
SET "number[0]=dummy"
FOR /f "usebackqdelims=" %%a IN ("%filename1%") DO (
IF DEFINED number[!count!] (SET /a count+=1&SET "name[!count!]=%%a") ELSE (SET "number[!count!]=%%a")
)
rem clear out dummy entry
SET "number[0]=dummy"
FOR /L %%c IN (1,1,%count%) DO (
rem replace spaces with dashes
SET "name[%%c]=!name[%%c]: =-!"
rem report to console rem report to console
ECHO Name: !name[%%c]! Number: !number[%%c]!
rem generate name.txt file
(
ECHO !name[%%c]!
ECHO !number[%%c]!
)>"%destdir%\!name[%%c]!.txt"
)
GOTO :EOF
You would need to change the values assigned to sourcedir and destdir to suit your circumstances. The listing uses a setting that suits my system.
I deliberately include spaces in names to ensure that the spaces are processed correctly.
I used a file named q65417881.txt containing your data for my testing.
The line data read from the file is assigned to %%a is assigned to and number[!count!] alternately. The data is retained in these arrays for use by further processing.
[Edited to include conversion of spaces within names to dashes]
If I understand correctly, you want to precede every second line with Number: + SPACE and every other line with Name: + SPACE. For this you do not need to store each line in a variable first, you can use a single for /F loop lo read the file line by line and process every line individually. There are two possibilities:
Temporarily precede every line with a line number plus : using findstr /N:
#echo off
rem // Loop through lines and precede each with line number plus `:`:
for /F "tokens=1* delims=:" %%K in ('findstr /N "^" "Test1.txt"') do (
rem // Calculate remainder of division by two:
set /A "MOD=%%K%%2" 2> nul
rem // Toggle delayed expansion to avoid issues with `!`:
setlocal EnableDelayedExpansion
rem // Conditionally return line string with adequate prefix:
if !MOD! neq 0 (
endlocal & echo Name: %%L
) else (
endlocal & echo Number: %%L
)
)
This will fail when a line begins with the a :.
Check whether numeric representation of current line string is greater than 0:
#echo off
rem // Loop through (non-empty) lines:
for /F "usebackq delims=" %%L in ("Test1.txt") do (
rem // Determine numeric representation of current line string:
set /A "NUM=%%L" 2> nul
rem // Toggle delayed expansion to avoid issues with `!`:
setlocal EnableDelayedExpansion
rem // Conditionally return line string with adequate prefix:
if !NUM! equ 0 (
endlocal & echo Name: %%L
) else (
endlocal & echo Number: %%L
)
)
This fails when a name begins with numerals and/or when a numeric line is 0.
And just for the sake of posting something different:
#SetLocal EnableExtensions DisableDelayedExpansion & (Set LF=^
% 0x0A %
) & For /F %%G In ('Copy /Z "%~f0" NUL') Do #Set "CR=%%G"
#For /F "Tokens=1,2* Delims=:" %%G In ('%__AppDir__%cmd.exe /D/V/C ^
"%__AppDir__%findstr.exe /NR "^[a-Z]*!CR!!LF![0123456789]" "Test1?.txt" 2>NUL"
') Do #(SetLocal EnableDelayedExpansion
(Set /P "=Name: %%I!CR!!LF!Number: " 0<NUL & Set "_="
For /F Delims^=^ EOL^= %%J In ('%__AppDir__%more.com +%%H "%%G"') Do #(
If Not Defined _ Set "_=_" & Echo %%J)) 1>"%%I.txt" & EndLocal)
This file should be run with the Test1.txt file in the current working directory. It is important that along side Test1.txt, there are no other .txt files with the same basename followed by one other character, (for example Test1a.txt or Test12.txt). Should you wish to change your filename, just remember that you must suffix its basename in the above code with a ? character, (e.g. MyTextFile.log ⇒ MyTextFile?.log).
I had the rare opportunity to verify that this script worked against the following example Test1.txt file:
Beth
1234567891
Jay
2134456544
Bob
2137856514
Jimmy
4574459540
Mary
3734756547
Gemma
6938456114
Albert
0134056504

How Can I Replace Any Line by Its Line Number?

EDIT: After great help from #aschipfl, the code is %110 as functional as I wanted it to be! I did some extra research and made it easy to use with prompts for that extra %10 :P
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Create a prompt to set the variables
set /p _FILETYPE="What file type: "
set /p _LINENUM="Which line: "
set /p _NEWLINE="Make line say: "
rem // Start the loop, and set the files
for %%f in (*%_FILETYPE%) do (
set "_FILE=%%f"
echo "_FILE=%%f"
rem // To execute seperate code before the end of the loop, starting at ":subroutine".
call :subroutine "%%f"
)
:subroutine
rem // Write to a temporary file:
> "%_FILE%.new" (
rem /* Loop through each line of the original file,
rem preceded by the line number and a colon `:`:*/
for /F "delims=" %%A in ('findstr /N "^" "%_FILE%"') do (
rem // Store the current line with prefix to a variable:
set "LN=%%A"
rem /* Store the line number into another variable;
rem everything up to the first non-numeric char. is regarded,
rem which is the aforementioned colon `:` in this situation: */
set /A "NUM=LN"
rem // Toggle delayed expansion to avoid trouble with `!`:
setlocal EnableDelayedExpansion
rem /* Compare current line number with predefined one and replace text
rem in case of equality, or return original text otherwise: */
if !NUM! equ %_LINENUM% (
echo(!_NEWLINE!
) else (
rem // Remove line number prefix:
echo(!LN:*:=!
)
endlocal
)
)
rem // Move the edited file onto the original one:
move /Y "%_FILE%.new" "%_FILE%"
endlocal
exit /B
ORIGINAL QUESTION:
Doesn't matter whats in any of the lines already. I just want to be able to pick any line from a .txt and replace it with whatever I choose.
So for example: Maybe I have a bunch of .txt's, and I want to replace line 5 in all of them with "vanilla". And later choose to replace line 10 of all .txt's with "Green". And so on...
I've seen lots of people asking the same main question. But I keep finding situational answers.
"How do I replace specific lines?" "you search for whats already in the line, and replace it with your new text" -I cant have that. I need it to be dynamic, because whats in each "line 5" is different, or there's lots of other lines with the same text.
I had tried the only one answer I could find, but all it ended up doing is replace literally all lines with "!ln:*:=!", instead of echoing.
#echo off
setlocal disableDelayedExpansion
set "file=yourFile.txt"
set "newLine5=NewLine5Here"
>"%file%.new" (
for /f "delims=" %%A in ('findstr /n "^" "%file%"') do for /f "delims=:" %%N in ("%%A") do (
set "ln=%%A"
setlocal enabableDelayedExpansion
if "!ln:~0,6!" equ "5:FMOD" (echo(!newLine5!) else echo(!ln:*:=!
endlocal
)
)
move /y "%file%.new" "%file%" >nul
The following (commented) code should work for you:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_FILE=yourFile.txt"
set "_NEWLINE=NewLine5Here"
set /A "_LINENUM=5" & rem // (target line number)
rem // Write to a temporary file:
> "%_FILE%.new" (
rem /* Loop through each line of the original file,
rem preceded by the line number and a colon `:`:*/
for /F "delims=" %%A in ('findstr /N "^" "%_FILE%"') do (
rem // Store the current line with prefix to a variable:
set "LN=%%A"
rem /* Store the line number into another variable;
rem everything up to the first non-numeric char. is regarded,
rem which is the aforementioned colon `:` in this situation: */
set /A "NUM=LN"
rem // Toggle delayed expansion to avoid trouble with `!`:
setlocal EnableDelayedExpansion
rem /* Compare current line number with predefined one and replace text
rem in case of equality, or return original text otherwise: */
if !NUM! equ %_LINENUM% (
echo(!_NEWLINE!
) else (
rem // Remove line number prefix:
echo(!LN:*:=!
)
endlocal
)
)
rem // Move the edited file onto the original one:
move /Y "%_FILE%.new" "%_FILE%"
endlocal
exit /B
Besides the typo in EnableDelayedExpansion in your code, you do not even need a second for /F loop to get the line number, and you do not need to extract a certain number of characters from the prefixed line text.
Note that this approach fails for line numbers higher than 231 - 1 = 2 147 483 647.
...is replace literally all lines with "!ln:*:=!", instead of echoing.
But that's correct, because the FINDSTR /N prefixes each line with a line number before.
The !ln:*:=! only removes the line number again.
And the findstr trick is used to avoid skipping of empty lines or lines beginning with ; (the EOL character).
The !line:*:=! replaces everthing up to the first double colon (and incuding it) with nothing.
This is better than using FOR "delims=:" because delims=: would also strip double colons at the front of a line.
The toggling of delayed expansion is necessary to avoid accidential stripping of ! and ^ in the line set "ln=%%A"
To fix your code:
setlocal DisableDelayedExpansion
for /f "delims=" %%A in ('findstr /n "^" "%file%"') do (
set "ln=%%A"
setlocal EnableDelayedExpansion
if "!ln:~0,6!" equ "5:FMOD" (
set "out=!newLine5!"
) else (
set "out=!ln:*:=!"
)
echo(!out!
endlocal
)

Parsing special characters in a for loop from a file to a variable

I'm trying to set a variable (Let's say, filehash is the variable name) from a file using batch file. Alas, I was stuck facing these two problems:
When it contains special characters, especially exclamation mark(s) as I'm using enableDelayedExpansion.
While doing that, I need to change & to & as well.
I've tried several solutions provided from various sources but none would fit my requirements.
Here's my current code:
#echo off
set grep=binaries\grep.exe
set fileindex=binaries\index.htm
set count=0
for /f "tokens=* delims=" %%a in (crc.dat) do (
set count=!count! + 1
set filehash=%%a
%grep% --ignore-case -w "!filehash!" %fileindex%>> list.dat
)
And an example of what's inside the crc.dat file:
Kabooom! Kablooey!
Kaboom & Kablooey
And the result using my current code above in list.dat:
Kabooom Kablooey
Kaboom & Kablooey
The result that I'm expecting in list.dat:
Kabooom! Kablooey!
Kaboom & Kablooey
I hope I conveyed my problem properly and thank you in advance!
To replace & by & in the input of grep, use this:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "grep=binaries\grep.exe"
set "fileindex=binaries\index.htm"
set "file=crc.dat"
set "list=list.dat"
rem // Initialise counter:
set /A "count=0"
> "%list%" (
for /F "usebackq delims=" %%a in ("%file%") do (
rem // Increment counter:
set /A "count+=1"
rem // Assign line string to variable:
set "lineitem=%%a"
rem // Toggle delayed expansion:
setlocal EnableDelayedExpansion
rem // Do sub-string replacement:
set "lineitem=!lineitem:&=&!"
rem // Execute `grep` command line:
"!grep!" --ignore-case -w "!lineitem!" "!fileindex!"
endlocal
)
)
rem // Return counter:
echo/%count%
endlocal
To replace & by & in the output of grep, use this:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "grep=binaries\grep.exe"
set "fileindex=binaries\index.htm"
set "file=crc.dat"
set "list=list.dat"
rem // Initialise counter:
set /A "count=0"
> "%list%" (
for /F "usebackq delims=" %%a in ("%file%") do (
rem // Increment counter:
set /A "count+=1"
rem // Execute `grep` command line and capture its output by `for /F`:
for /F "delims=" %%b in ('^""%grep%" --ignore-case -w "%%a" "%fileindex%"^"') do (
rem // Assign `grep` output to variable:
set "lineitem=%%b"
rem // Toggle delayed expansion:
setlocal EnableDelayedExpansion
rem // Do sub-string replacement:
set "lineitem=!lineitem:&=&!"
rem // Return modified string:
echo(!lineitem!
endlocal
)
)
)
rem // Return counter:
echo/%count%
endlocal
In general, to handle strings with exclamation marks, you must toggle delayed expansion, so that normal %-expanded variables and for variable references like %%a become expanded with delayed expansion disabled.
This is a solution which is delayedExpansion-free and able to replace & to &.
#echo off
set grep=binaries\grep.exe
set fileindex=binaries\index.htm
set count=0
for /f "tokens=* delims=" %%a in (crc.dat) do (
set /a count+=1
%grep% --ignore-case -w "%%a" %fileindex%>>temp.dat
)
powershell -Command "(gc temp.dat) -replace '&', '&' | sc list.dat"
del /f temp.dat
pause
exit /b
Some changed things:
set /a count+=1 = set /a count=%count%+1
The !fileHash! points to %%a, so why do we need it? %%a will work.
The powershell command replaces & with &.
Output the replaced content into the file.
Delete a temp file used.

Windows Batch file count numbers of tokens

I have this batch file:
#ECHO OFF
SETLOCAL EnableDelayedExpansion
IF EXIST OPERATORS_FULL.csv DEL OPERATORS_FULL.csv
IF EXIST OPERATORS_FULL.tmp DEL OPERATORS_FULL.tmp
FOR %%A IN ( OPERATORS_*.csv ) DO (
:: get attribute from filename
SET "attr=%%A"
SET "attr=!attr:OPERATORS_=!"
SET "attr=!attr:.csv=!"
:: split string to get date suffix
FOR /F "tokens=1,2 delims=_" %%G IN ( "!attr!" ) DO (
SET attr=%%G
SET date_=%%H
)
:: dump CSVs, skipping each header line, adding the attributes from the filename
FOR /F "skip=1 tokens=*" %%G IN ( %%A ) DO ECHO %%G;!attr!;!date_! >> OPERATORS_FULL.tmp
)
REN OPERATORS_FULL.tmp OPERATORS_FULL.csv
The attr value is variable and it can contain 1,2,3,4,... of "_" character.
So the tokens=1,2 is not functionally everytime.
I want the last token of the "attr" variable.
Any suggestions?
UPDATE
I tried this:
#ECHO OFF
SETLOCAL EnableDelayedExpansion
IF EXIST Operatori_FULL.csv DEL Operatori_FULL.csv
IF EXIST Operatori_FULL.tmp DEL Operatori_FULL.tmp
FOR %%A IN ( Operatori_*.csv ) DO (
:: get attribute from filename
SET "attr=%%A"
SET "attr=!attr:Operatori_=!"
SET "attr=!attr:.csv=!"
set "date_=!attr!"
:loop
if "!date_:_=!" == "!date_!" goto :gotdate
for /f "delims=_ tokens=1,*" %%g in ("!date_!") do echo %%h
pause
goto :loop
:gotdate
:: dump CSVs, skipping each header line, adding the attributes from the filename
FOR /F "skip=1 tokens=*" %%G IN ( %%A ) DO ECHO %%G;!attr!;!date_! >> Operatori_FULL.tmp
)
REN Operatori_FULL.tmp Operatori_FULL.csv
But the snippet remove only the first part of string (A2A_)
This code extracts the last token from attr variable and store it in date_ variable:
rem split string to get date suffix
set "newAttr="
set "date_="
FOR %%G IN ( "!attr:_=" "!" ) DO (
SET "newAttr=!newAttr!_!date_!"
SET "date_=%%~G"
)
SET "attr=!newAttr:~2!"
If you just need the last token, the code is simpler:
FOR %%G IN ( "!attr:_=" "!" ) DO SET "date_=%%~G"
Here is a possible solution, that replaces every _ by a line-break temporarily:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "STRING=%~1" & rem // (first argument is taken as input string)
set "CHAR=_" & rem // (this is the character of interest)
rem // Build line-break:
(set ^"LF=^
%= empty line =%
^")
rem /* Replace each predefined character by a line-break,
rem and enclose every line string portion within `""`;
rem these quotation marks are needed to handle empty strings: */
setlocal EnableDelayedExpansion
if defined STRING set ^"STRING=^"!STRING:%CHAR%=^"^%LF%%LF%^"!^"^"
rem /* Loop through all the lines in the modified string and
rem assign each line string portion to a variable with
rem the surrounding `""` removed; when the loop is finished,
rem the last line is stored in the variable: */
for /F delims^=^ eol^= %%S in ("!STRING!") do (
endlocal
set "LAST=%%~S"
setlocal EnableDelayedExpansion
)
rem // Return string portion behind last predefined character:
echo(!LAST!
endlocal
endlocal
exit /B
Hopefully this will be close to what you want (not sure whether attr will be what you need):
#ECHO OFF
SETLOCAL EnableDelayedExpansion
IF EXIST Operatori_FULL.csv DEL Operatori_FULL.csv
IF EXIST Operatori_FULL.tmp DEL Operatori_FULL.tmp
FOR %%A IN ( Operatori_*.csv ) DO (
:: get attribute from filename
SET "attr=%%A"
SET "attr=!attr:Operatori_=!"
SET "attr=!attr:.csv=!"
set "date_=!attr!"
call :getLast
:: dump CSVs, skipping each header line, adding the attributes from the filename
FOR /F "skip=1 tokens=*" %%G IN ( %%A ) DO ECHO %%G;!attr!;!date_! >> Operatori_FULL.tmp
)
REN Operatori_FULL.tmp Operatori_FULL.csv
goto :eof
:getLast
if "!date_:_=!" == "!date_!" goto :eof
for /f "delims=_ tokens=1,*" %%g in ("!date_!") do set "date_=%h"
goto :getLast
The subroutine getLast will strip date_ to its last component (delimited by underscores). Its operation is: while there's an underscore in date_ it splits it into "the first token" and "all the rest" and sets date_ to "all the rest". When there are no (more) underscores, date_ is left with the last underscore-delimited component of its original value.
The "underscore stripping code" needs to be a "subroutine" since you cannot (to the best of my knowledge) use labels inside the outer for loop.

Replace n-th element in CSV string

I try to replace the n-th element of a CSV string, without knowing his value. For example, here is my string :
*;*;*;element_to_replace;*;*
With * an undefined string, it can be anything.
So i tried to use :
for /F "delims=" %%w in (file\workstation) do (
set line=%%w
if !compt! NEQ 0 (
set new_line=!line:*;*;*;*=*;*;*;new_value!
#echo !new_line! >> file\tmp_workstation
) else (
#echo !header_workstation! >> file\tmp_workstation
)
set /A "compt+=1"
)
It doesn't work. Am i doing something wrong ?
#echo off
setlocal enabledelayedexpansion
REM you want to replace token 4:
for /f "tokens=1-4,* delims=;" %%a in (t.csv) do (
echo %%a;%%b;%%c;replaced;%%e
)
tokens=1-4,* means: take the first four tokens, the fifth token is "the rest of the line". %%a is the first token, %%b is the second one etc.
You want to write token1;token2;token3,"replacement string for the fourth token(%%d)";"rest of the line" (fifth token).
Supposing the * characters do not appear literally within your data and it does also not contain any ? marks, you could use the following code snippet:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "INFILE=file\workstation"
set "OUTFILE=file\tmp_workstation"
set "SEPARATOR=;"
set /A "COL_NUM=4"
set "COL_NEWVAL=new_value"
rem // A single redirection:
> "%OUTFILE%" (
set "HEADER=#"
rem // Read CSV file line by line:
for /F usebackq^ delims^=^ eol^= %%L in ("%INFILE%") do (
set "LINE=%%L"
if defined HEADER (
rem // Skip header from replacement:
set "NEW_LINE=%%L"
set "HEADER="
) else (
set "NEW_LINE=" & set "SEP=" & set /A "IDX=0"
rem // Toggle delayed expansion to not lose any `!`:
setlocal EnableDelayedExpansion
set "LINE=!LINE:"=""!^"
rem // Use standard `for` loop to enumerate column values:
for %%I in ("!LINE:%SEPARATOR%=","!") do (
endlocal
set /A "IDX+=1"
set "ITEM=%%~I"
setlocal EnableDelayedExpansion
rem // Replace column value if index matches:
if !IDX! EQU %COL_NUM% (
endlocal
set "ITEM=%COL_NEWVAL%"
setlocal EnableDelayedExpansion
) else (
if defined ITEM set "ITEM=!ITEM:""="!^"
)
rem /* Collect line string;
rem `for /F` loop to pass string beyond `endlocal` barrier: */
for /F delims^=^ eol^= %%E in ("!NEW_LINE!!SEP!!ITEM!") do (
endlocal
set "NEW_LINE=%%E"
setlocal EnableDelayedExpansion
)
endlocal
set "SEP=%SEPARATOR%"
setlocal EnableDelayedExpansion
)
endlocal
)
rem // Output newly built line:
setlocal EnableDelayedExpansion
echo(!NEW_LINE!
endlocal
)
)
endlocal
exit /B

Resources