Solved empty line to single line in bat file

January 28, 2015 at 18:32:16
Specs: Windows 7
can someone please help me with this in .bat
i have a text file(res.txt) that looks like this
1;
a
2;
b
3;
c

the output on another text file(res2.txt) should be like this
1;a
2;b
3;c

but my code is giving an o/p of
1; a 2; b 3; c

here is my code
@echo off
setlocal enableextensions disabledelayedexpansion

set "first=1"
<nul (
for /f "usebackq tokens=* delims=" %%a in ("res.txt") do (
if defined first (set /p ".=%%a " & set "first=") else (set /p ".=%%a ")
)
)>"res2.txt"

THANKS..
help will be much appreciated..


See More: empty line to single line in bat file

Report •


#1
January 28, 2015 at 21:59:15
✔ Best Answer
::====== script starts here ===============
:: If your file is strictly as posted:
:: namit.bat 2015-01-29 10:45:00.06
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

set/a N=0

:main
for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
set S=!S!%%a
if !N! equ 2 (
echo.!S!
set/a N=0
set S=
)
) >> NEWFILE
goto :eof
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
January 29, 2015 at 06:07:47
thanks that works great..

Report •

#3
January 29, 2015 at 07:36:49
another question..
how can i edit a text file putting numbers in every line..
say i have text1.txt
A;a
B;b
C;c

and i want to put a number in each every line that looks like this

1. A;a
2. B;b
3. C;c


thanks in advance..


Report •

Related Solutions

#4
January 29, 2015 at 20:16:48
::====== script starts here ===============
:: prepend line numbers
:: namit2.bat 2015-01-30 11:13:53.68
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

set /a N=0
:main
for /f "tokens=* delims= " %%a in (myfile) do (
set/a N+=1
echo !N!. %%a
) >> NEWFILE
goto :eof
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •


Ask Question