Computing.Net > Forums > Programming > Delete blank lines from a text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete blank lines from a text file

Reply to Message Icon

Name: MC
Date: July 11, 2006 at 11:40:09 Pacific
OS: XP
CPU/Ram: ?
Product: IBM thinkpad T43
Comment:

I am trying to delete blank lines from a text file when executing my batch file.

I used the code found on this site
@Echo off
For /F "tokens=1 delims=" %%A in (c:\orig.txt) Do Echo %%A >> c:\new.txt

But when I open the file it still contains blank lines (spaces) and has the text "Echo if off."

Any help would be appreciated.

Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: July 11, 2006 at 12:29:03 Pacific
Reply:

@Echo Off
For /F "tokens=* delims=" %%A in (C:\orig.txt) Do Call :NOBLANK %%A
GoTo :EOF

:NOBLANK
If "%*"=="" GoTo :EOF
Echo %* >> C:\new.txt
GoTo :EOF

Note that the For /F statement fits just ONE line ending with :NOBLANK %%A


0

Response Number 2
Name: Mechanix2Go
Date: July 11, 2006 at 13:28:30 Pacific
Reply:

Hi IVO,

This gets out the blank lines and preserves the indents:

@Echo Off
For /F "tokens=* delims=" %%A in (e.bak) Do (
Echo %%A >> new.txt )


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 3
Name: Derek
Date: July 27, 2006 at 19:25:11 Pacific
Reply:

Re #1.

The poster is trying to use a "batch file" to delete blank lines from text files. That's what all the code is about.

DerekW


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


PHP: opendir() error Forfiles command help



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Delete blank lines from a text file

Delete Last line of a text file www.computing.net/answers/programming/delete-last-line-of-a-text-file/20179.html

Extract Lines from a Text File www.computing.net/answers/programming/extract-lines-from-a-text-file/13817.html

delete x number of lines from a CSV file www.computing.net/answers/programming/delete-x-number-of-lines-from-a-csv-file/19820.html