Combining multiple newline to 1

March 16, 2009 at 00:44:32
Specs: Windows XP
How do i combine

1>> ***title***
2>>
3>>name
4>>
5>>
6>>
7>> ***title***
8>>
9>>name

to become
1>> ***title***
2>>name
3>>
4>> ***title***
5>>name


See More: Combining multiple newline to 1

Report •


#1
March 16, 2009 at 00:46:03
The code i wrote is as below

@Echo Off > bb.txt
SETLOCAL ENABLEDELAYEDEXPANSION

For /F "tokens=* delims=" %%A in (aa.txt) Do (
ECHO %%A >> bb.txt
)


Report •

#2
March 16, 2009 at 07:04:33
lol, i just realized it is simple as this.

type aa.txt|more/s >bb.txt

on second thought, i see you dont want to keep single line.


Report •

#3
March 16, 2009 at 17:30:04
Reno, thnx for replying....
i have already solve the problem as below...

@Echo Off > Temp.txt
SETLOCAL ENABLEDELAYEDEXPANSION

For /F "tokens=* delims=" %%A in (aa.txt) Do (

REM NEW LINE
FINDSTR /E "***" %%A
IF NOT ERRORLEVEL 1 ECHO. >> Temp.txt

REM DATA
ECHO %%A >> Temp.txt
)


Report •

Related Solutions

#4
March 16, 2009 at 20:57:01
it's not working:

C:\batch>newline.bat
FINDSTR: Cannot open ***title**
FINDSTR: Cannot open name
FINDSTR: Cannot open ***title***
FINDSTR: Cannot open name

C:\batch>type temp.txt
***title**
name
***title***
name

there is no blank line between line 2 & 3 as of your original question on post #1.
if you want to eliminate all blank line, this can be achieved with simple for loop or piping type to findstr as below:

C:\batch>for /f "tokens=*" %a in (test.txt) do @echo %a
***title**
name
***title***
name

C:\batch>type test.txt|findstr "."
***title**
name
***title***
name


Report •

#5
March 16, 2009 at 22:01:31
Reno, thnx for noticing...
It work wonder only after i added space between title & ***

1>> *** title ***
2>>
3>>name
4>>
5>>
6>>
7>> *** title ***
8>>
9>>name

to become
1>>
2>> *** title ***
3>>name
4>>
5>> *** title ***
6>>name


Report •

#6
March 16, 2009 at 23:19:23
FINDSTR /E "***" %%A
the following usage is incorrect as it treat %%A as file and actually try to open it. but i dont know why the above line DID actually give the correct result even though it gives me a long list of error(s).

correct usage should be:
echo %%A | findstr/e "***" >nul

the following will work if it found "***" at end of string whether it has space between it or not.

C:\batch>for /f "tokens=*" %a in (test.txt) do @echo %a|findstr/e "***" >nul && (echo.) & echo %a

***title***
name

***title ***
name


Report •

#7
March 17, 2009 at 17:11:50
Reno, thnx a lot thr....

It is a much more correct answer than what i wrote..... thnx...


Report •


Ask Question