lesgetdown
asked on
Batch - take list conver to delimited format and add new line
this is an expansion of a previous question asked
https://www.experts-exchange.com/questions/24343086/Batch-take-list-and-convert-to-delimited-format.html
I am querying a list
A
B
C
D
E
F
that i need to Display in the format of
A B
C D
E F
...
thx!
https://www.experts-exchange.com/questions/24343086/Batch-take-list-and-convert-to-delimited-format.html
I am querying a list
A
B
C
D
E
F
that i need to Display in the format of
A B
C D
E F
...
thx!
ASKER
that works, but seems to cut out the first variable.
instead of A B
i get <blank> B
everything else displays properly
instead of A B
i get <blank> B
everything else displays properly
Hiya... Apologies for the intrusion to all those already present.
Does the following code give you the results you're looking for?
@echo off
setlocal enabledelayedexpansion
set tmp=
(for /f "tokens=*" %%a in (list1.txt) do (
if not defined tmp (
set tmp=%%a
) else (
echo !tmp! %%a
set tmp=
)
))>list2.txt
if defined tmp echo %tmp%>>list2.txt
Does the following code give you the results you're looking for?
@echo off
setlocal enabledelayedexpansion
set tmp=
(for /f "tokens=*" %%a in (list1.txt) do (
if not defined tmp (
set tmp=%%a
) else (
echo !tmp! %%a
set tmp=
)
))>list2.txt
if defined tmp echo %tmp%>>list2.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh... without the redirection to another file, this will simply output the results to the screen.
@echo off
setlocal enabledelayedexpansion
set tmp=
for /f "tokens=*" %%a in (list1.txt) do (
if not defined tmp (
set tmp=%%a
) else (
echo !tmp! %%a
set tmp=
)
)
if defined tmp echo %tmp%
@echo off
setlocal enabledelayedexpansion
set tmp=
for /f "tokens=*" %%a in (list1.txt) do (
if not defined tmp (
set tmp=%%a
) else (
echo !tmp! %%a
set tmp=
)
)
if defined tmp echo %tmp%
ASKER
Both ways work perfectly!
Oh! Hiya Qlemo.... Your code works well. It's amazing how different our approaches are yet both perform as expected.
They both handle blank lines, multiple blank lines, lines with spaces, even number of lines and odd number of lines.
Not bad eh?
They both handle blank lines, multiple blank lines, lines with spaces, even number of lines and odd number of lines.
Not bad eh?
Wow! That was unexpectedly quick....
Thank you.
Thank you.
@echo off
setlocal EnableDelayedExpansion
set line=
set no=0
for /F "tokens=*" %%L in (file.txt) do (
if !no! == 0 if defined line (echo. !line!) & set line=%%L
if !no! == 1 set line=!line! %%L
set /A no=1-no
)
echo %line%