Computing.Net > Forums > Disk Operating System > removing empty lines in textfile

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.

removing empty lines in textfile

Reply to Message Icon

Name: Miskva
Date: July 19, 2002 at 05:08:08 Pacific
Comment:

Hi,
I've generated a text file, with a specific program, but the problem is I need to run this file against another program, and it doesn't accept empty lines in between text.

The program is not able to generate it without empty lines, I tried that.

Question then remains, I have a simple text file, with empty lines. How do I remove the empty lines ?

I do have an sed.exe (non-MKS), but even here I can't get it to work.



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 19, 2002 at 13:13:25 Pacific
Reply:

I reckon SED.exe can do it, but I'm not certain, and I don't remember hot to use it.

The trick is to replace the ocurrances of (characters in hex values) "DADA" by "DA". D is the Carriage Return character, and A is the Line Feed character. Together, they make the CR/LF pair, which marks a line break. If you have a double line break, you have a blank line.

You can use another utility, SBS2.COM, which is what this batch file does:

===== BATCH SCRIPT BEGIN =====
@echo off

if "%1"=="" for %%? in (echo goto:help) do %%? Missing parameter
if not exist %1 for %%? in (echo goto:help) do %%? File not found - %1
goto start
:help
echo SINTAX: %0 targetfile
goto eof

:start
:: ASCII assembler by Hebert Kleebauer
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>%TEMP%.\SBS2.COM
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU!WvX0GwUY Wv;ovBX2Gv0ExGIuht6>>%TEMP%.\SBS2.COM
echo ?@}IKuNWpe~Fpe?FNHlF?wGMECIQqo{Ox{T?kPv@jeoSeIlRFD@{AyEKj@>>%TEMP%.\SBS2.COM
echo iqe~1NeAyR?mHAG~BGRgB{~H?o~TsdgCYqe?HR~upkpBG?~slJBCyA?@xA>>%TEMP%.\SBS2.COM
echo LZp{xq`Cs?H[C_vHDyB?Hos@QslFA@wQ~~x}viH}`LYNBGyA?@xAB?sUq`>>%TEMP%.\SBS2.COM
echo LRy@PwtCYQEuFK@A~BxPtDss@fFqjVmzD@qBEOEenU?`eHHeBCMs?FExep>>%TEMP%.\SBS2.COM
echo LHsPBGyA?@xAunjzA}EKNs@CA?wQpQpKLBHv?s`WJ`LRCYyIWMJaejCksl>>%TEMP%.\SBS2.COM
echo H[GyFGhHBwHZjjHeoFasuFUJeHeB?OsQH[xeHCPvqFj@oq@eNc?~}Nu??O>>%TEMP%.\SBS2.COM
echo ~oEwoAjBKs?Zp`LBzHQzyEFrAWAG{EFrAqAGYwHTECIQ{coKIsaCsf{Oe~>>%TEMP%.\SBS2.COM
echo CK}Ayre~CNFA{rAyEKFACrA{EKGAjbA}eKGSjNMtQFtc{OAyDGFj?{FDGQ>>%TEMP%.\SBS2.COM
echo KAjNVk_OCAx@e?f{o?CosI}1EGizhljJ~H1ZeG}JBA~rACBMDGjjDG@g0>>%TEMP%.\SBS2.COM

:loop
type %1 > %TEMP%.\TEMP.DAT
%TEMP%.\SBS2.COM 0 "$0d$0a$0d$0a" "$0d$0a" < %TEMP%.\TEMP.DAT > %1
if errorlevel=1 goto loop

del %TEMP%.\SBS2.COM
del %TEMP%.\TEMP.DAT
:eof
===== BATCH SCRIPT END =====

Watch out for line wrapping!

No external file is needed: the batch file creates SBS2.COM, uses it and deletes it.

The sintax is:

filename.bat targetfile

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 2
Name: Mike Newcomb
Date: July 21, 2002 at 01:20:32 Pacific
Reply:

If there are not too many blank lines and you are happy to remove them manually, why not simply use edit or edlin. Usually CNTRL + Y removes the line the cursor is on. Alternatively a word processor will do the job and thenoutput as an ascii file.
Good luck! u


0

Response Number 3
Name: Miskva
Date: July 21, 2002 at 05:12:50 Pacific
Reply:

Thanks, I try the script you mention, it looks sort of weird, but if it works, I am more than happy to use it !

Will post if it works or not ...

Anyway, Mike, thanks for the info also, but I need to do it in batch ..


0

Response Number 4
Name: Miskva
Date: July 21, 2002 at 06:02:14 Pacific
Reply:

Doesnt seem to work

creates batchfile, but this com file doesnt do anything, creates no output whatsoever


0

Response Number 5
Name: Miskva
Date: July 21, 2002 at 09:26:31 Pacific
Reply:

looks like it is somewhat easier via sed

sed "/^$/d"

does the job

thanks all anyway


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

dual boot nt and Dos true bootable cd-rom



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: removing empty lines in textfile

Removing blank characters in batch www.computing.net/answers/dos/removing-blank-characters-in-batch/16121.html

New line in a batch file www.computing.net/answers/dos/new-line-in-a-batch-file/4750.html

deleting multiple lines in txt file www.computing.net/answers/dos/deleting-multiple-lines-in-txt-file/15605.html