Link to home
Start Free TrialLog in
Avatar of j-heart
j-heartFlag for United States of America

asked on

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

Avatar of knightEknight
knightEknight
Flag of United States of America image

findstr  .  myfile.txt > myNewFile.txt
Avatar of j-heart

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oBdA
oBdA

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"
)