How can I delete all blank lines from a plain text file?

C

CX

I have plain text files that have an unknown number of blank lines that I
need to eliminate. Here's a small sample/section of one of them (the ... just
means that there's more text before and after the section):

....
PAMTRAK FORT WASHI
MTKT# 5544043092119 10/06
^

D10/06/2005
N70020051006
T198.00
....


As you can see there's a blank line between the one that has a single ^ on
it and the one beginning with the letter "D". I need to keep all lines that
have text, including those that have the "^" on them and delete the only
blank ones. I can do this manually, but not for files that have a bazillion
lines in them.

I opened the file in Word 2000, clicked the Show/Hide button and it seems
every single line ends with a paragraph character (whatever that reverse P
thing is called). Anyway, I tried to Find and Replace without luck because I
have no idea how to search for the blank line.

As you can see I'm stumped. Anyhow, I'm willing to use ANY application
including DOS ones to get this to happen so any non-Word suggestions are also
welcome.

Thanks to all who respond in advance!
 
D

Daiya Mitchell

You can Find and Replace a paragraph mark with nothing to delete blank
lines.

First make sure that the blank lines are a paragraph mark--click ¶ on the
standard toolbar and you should see a ¶ (paragraph mark) on the empty lines.

To tell Word to Find a paragraph mark, click on More in the Find dialog,
then use the Special menu (you'll see all sorts of options). You can type
in the code as well.
 
S

Suzanne S. Barnhill

Replacing ^p with nothing will combine all the text into one huge paragraph.
What you want to do is replace ^p^p (two successive paragraph marks) with
^p. This will fail if there is any space on the blank line, so be sure to
display nonprinting characters (Ctrl+*) and look for spaces (dots). You can
remove those first by searching for <space>^p (where "<space>" indicates a
press of the Spacebar in the "Find what" box) and replacing with ^p.
 
C

CX

Thanks for the quick response!
But after reading my description of the problem, I don't think I was clear
enough. What I meant to say was that every line, blank or otherwise,
currently ends with a paragraph mark. I don't wan't to delete the paragraph
marks on the lines that do have text. I only want to delete the lines that
have no text, including their paragraph marks.

* I went ahead and added the paragraph marks as they appear in Word into the
original example below.

So basically, I want to have the sample to end up like this after removing
jus the blank line:

....
PAMTRAK FORT WASHI¶
MTKT# 5544043092119 10/06¶
^¶
D10/06/2005¶
N70020051006¶
T198.00¶
....

Hope this makes more sense and thanks again.
 
C

CX

ah, your reply came in after my re-explanation post, but you nailed it! I
just tried it and it worked perfectly. thank you, thank you, thank you!

And yes, all blank lines in these files never have spaces.

btw, how can I automate this process? I would love to just open a file have
a macro or some other means to make this as easy as possible. And while I'm
at it, how can I distribute the macro to others that may need it? (don't ask
why)
 
D

Daiya Mitchell

Ouch. Thanks for catching that. :)


Replacing ^p with nothing will combine all the text into one huge paragraph.
What you want to do is replace ^p^p (two successive paragraph marks) with
^p. This will fail if there is any space on the blank line, so be sure to
display nonprinting characters (Ctrl+*) and look for spaces (dots). You can
remove those first by searching for <space>^p (where "<space>" indicates a
press of the Spacebar in the "Find what" box) and replacing with ^p.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top