Articles

Solved Delete blank lines with batch file?

July 11, 2005 at 11:15:35
Specs: WinXP, 512

Hey all, I can usually handle any issues I have using the Search (really great, btw), but I couldn't find anything on this particular question:

How do you delete blank lines in a .txt file?

Here's an example:

abs123
g53ytv53y
35v

4w6u6i
6u
6un56i7

6uen6u

I want the above to read:

abs123
g53ytv53y
35v
4w6u6i
6u
6un56i7
6uen6u

?


See More: Delete blank lines with batch file?

Report •


#1
July 11, 2005 at 12:54:52

If you are doing a small number of files use a text processor and replace the successive newline characters with a single newline character. If you are doing many write a small utility program.

Report •

#2
July 11, 2005 at 14:38:36
✔ Best Answer

Use the following simple (just one line!) batch to remove blank lines from a txt file

@Echo Off

For /F "tokens=* delims=" %%A in (%1) Do Echo %%A >> %2

where %1 is the source file and %2 the result, i.e.

Clean Mytext.txt MyText.new

assumed you named the batch Clean.bat.
That works under Win NT/XP/2K only.


Report •

#3
July 11, 2005 at 15:33:25

i thought the forum security guy and the admin decided all these batch file posts should be in the DOS section...

GIMPS


Report •

Related Solutions

#4
July 11, 2005 at 23:19:32

This batch file won´t work in DOS.

Report •

#5
July 11, 2005 at 23:54:41

gimmpy,

News to me.

M2


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


Report •

#6
July 12, 2005 at 09:28:04

gimmpy255:
I think the only thing decided was that only questions on batch files that work in 'real' standalone DOS could be posted in the DOS area. There is still some question of what is considered a 'program'.

Report •

#7
July 12, 2005 at 12:42:38

Thanks, IVO! Works great!

Report •

#8
July 13, 2005 at 21:37:01

I have asimilar question and I am not sure how to modify your answer to fit my needs, could you point me in the right direction.

here it is:

I have a text file with the following info:


lm_loweralpha-numeric#1-oxid#299.rt:
15999984 bytes read, disk access time:0.61 s
verifying the file...
searching for 1 hash...
cryptanalysis time: 0.00 s

statistics
----------------
plaintext found: 0 of 4 (0.00%)
total disk access time: 30.23 s
total cryptanalysis time: 0.76 s
total chain walk step: 771903
total false alarm: 455
total chain walk false alarm: 184850

result
----------------
af6e956c6 <notfound> hex:<notfound>
af6e956c6 <notfound> hex:<notfound>
af6e956c6 <notfound> hex:<notfound>
f367ef4ff <notfound> hex:<notfound>
f367ef4ff <notfound> hex:<notfound>
e165f0192 <notfound> hex:<notfound>


the file is named cracked.txt

from a batch file, I would like to delete all of the lines of text up to and including the

result
----------------

so that when the batch file is complete, all that will be left in the file is:

af6e956c6 <notfound> hex:<notfound>
af6e956c6 <notfound> hex:<notfound>
af6e956c6 <notfound> hex:<notfound>
f367ef4ff <notfound> hex:<notfound>
f367ef4ff <notfound> hex:<notfound>
e165f0192 <notfound> hex:<notfound>


Since I will never be certain how many lines will proceed the hashes, what command should I use to edit the text file from a batch file.

Thank you,

Ramius



Report •

#9
July 14, 2005 at 00:45:23

Hi Ranius,

Try this. Your output winds up in CRACKED.NEW

::=========== cracked stripper ====
@echo off > cracked.new
set keep=NO

for /f %%L in (cracked.txt) do call :keeper %%L
goto :eof

:keeper

if %keep%==YES echo %1 >> cracked.new
echo %1|find "result" > nul
if not errorlevel 1 set keep=YES
::======

M2


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


Report •


Ask Question