Computing.Net > Forums > Programming > Delete blank lines with batch 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 with batch file?

Reply to Message Icon

Name: hybridreams
Date: July 11, 2005 at 11:15:35 Pacific
OS: WinXP
CPU/Ram: 512
Comment:

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

?



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: July 11, 2005 at 12:54:52 Pacific
Reply:

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.


0

Response Number 2
Name: IVO
Date: July 11, 2005 at 14:38:36 Pacific
Reply:

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.


0

Response Number 3
Name: gimmpy225
Date: July 11, 2005 at 15:33:25 Pacific
Reply:

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

GIMPS


0

Response Number 4
Name: uli_glueck
Date: July 11, 2005 at 23:19:32 Pacific
Reply:

This batch file won´t work in DOS.


0

Response Number 5
Name: Mechanix2Go
Date: July 11, 2005 at 23:54:41 Pacific
Reply:

gimmpy,

News to me.

M2


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


0

Related Posts

See More



Response Number 6
Name: wizard-fred
Date: July 12, 2005 at 09:28:04 Pacific
Reply:

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'.


0

Response Number 7
Name: hybridreams
Date: July 12, 2005 at 12:42:38 Pacific
Reply:

Thanks, IVO! Works great!


0

Response Number 8
Name: Ramius
Date: July 13, 2005 at 21:37:01 Pacific
Reply:

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



0

Response Number 9
Name: Mechanix2Go
Date: July 14, 2005 at 00:45:23 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






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 with batch file?

Delete blank lines from a text file www.computing.net/answers/programming/delete-blank-lines-from-a-text-file/14525.html

Get last line with batch file www.computing.net/answers/programming/get-last-line-with-batch-file/17019.html

Deleting lines with batch files www.computing.net/answers/programming/deleting-lines-with-batch-files/13330.html