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

Delete blank lines from a text file

Reply to Message Icon

Original Message
Name: MC
Date: July 11, 2006 at 11:40:09 Pacific
Subject: Delete blank lines from a text file
OS: XP
CPU/Ram: ?
Model/Manufacturer: 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!


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: July 11, 2006 at 12:29:03 Pacific
Subject: Delete blank lines from a text file
Reply: (edit)

@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


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: July 11, 2006 at 13:28:30 Pacific
Subject: Delete blank lines from a text file
Reply: (edit)

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



Report Offensive Follow Up For Removal

Response Number 3
Name: Derek
Date: July 27, 2006 at 19:25:11 Pacific
Subject: Delete blank lines from a text file
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Delete blank lines from a text file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge