Remove blank lines in a text file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Remove blank lines in a text file?

#1 Post by tinfanide » 29 Jan 2012 20:13

a.txt:
This is a line.

This is a line.


This is a line.


I tried different ways but failed:

Code: Select all

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

Code: Select all

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

Code: Select all

TYPE a.txt | FINDSTR /V /R ^ $

Aacini
Expert
Posts: 1930
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Remove blank lines in a text file?

#2 Post by Aacini » 29 Jan 2012 21:52

a.txt wrote:This is a line.

This is a line.


This is a line.

Code: Select all

For /F "delims=" %%A in (a.txt) Do Echo %%A

Output.txt wrote:This is a line.
This is a line.
This is a line.

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: Remove blank lines in a text file?

#3 Post by tinfanide » 30 Jan 2012 08:23

Code: Select all

For /F "delims=" %%A in (a.txt) Do Echo %%A


FOR /F : loop thru texts
"delims=" : default=<tab><space> ?
Why "delims=" could return carriage return?
Could ya explain a little bit?

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Remove blank lines in a text file?

#4 Post by !k » 30 Jan 2012 10:02

tinfanide wrote:"delims=" : default=<tab><space> ?
No.
"delims=" == NO delims
default (<tab><space>) is no delims=...


------------------------------------

Code: Select all

FINDSTR /V /R /C:"^$" a.txt

Post Reply