How to Remove Blank Lines from text file in msdos?

I have a program that generates a CSV file with extra blank lines at the end.  It is never the same number of lines and the file name changes each time the program is run but always starts out with "APPTS" and ends with the "TXT" extension.
I am looking for a batch file that will remove all the blank lines but keep the file name the same.
It also needs to work with wildcards.
Running it from the command line should look something like this:

Clean.bat appts*.txt

j-heartAsked:
Who is Participating?
 
oBdACommented:
Try this:
@echo off
setlocal
set FileMask=%~1
for %%a in ("%FileMask%") do (
  ren "%%a" "%%~na.old"
  findstr . "%%~dpna.old" "%%a"
)

Open in new window

0
 
knightEknightCommented:
findstr  .  myfile.txt > myNewFile.txt
0
 
j-heartAuthor Commented:
This works only if I know the file name in advance.
If I use a wildcard it appends the file name to the beginning of each line.

So if I run:

findstr  .  myfile.txt > myNewFile.txt

The output to file myNewFile.txt is perfect.

But if I run

findstr  .  myfile*.txt > myNewFile.txt

Then each line starts with the filename:

"myfile.txt:"

Since the program that generates the CSV file generates a rather random series of underscores and numbers after the "appts" begining, I need to be able to use wildcards.
0
 
oBdACommented:
Sorry, the redirection got lost in line 6:
@echo off
setlocal
set FileMask=%~1
for %%a in ("%FileMask%") do (
  ren "%%a" "%%~na.old"
  findstr . "%%~dpna.old" >"%%a"
)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.