Link to home
Create AccountLog in
Avatar of calju
calju

asked on

DOS script to delete empty lines inside the file

I want to create DOS batch file to loop through file (text files) and delete all empty lines.
Avatar of JoshdanG
JoshdanG

@echo off
type nul > output.txt
for /f "delims=" %%i in (%1) do echo %%i>> output.txt

--------------------------
Save as your_name.bat

usage: your_name file_to_parse.txt

Outputs all non-empty lines in file_to_parse to output.txt

Note that it intentionally wipes out output.txt before writing (just remove the second line to make it always append), and it also puts an endline on the last line even if you did not have one before.  Please let me know if either of these are an issue.
Avatar of calju

ASKER

Thanx,

But if I want to sweep same file not output to output.txt? So I can use syntax like clean.bat and filename to clean is specified inside clean.bat
ASKER CERTIFIED SOLUTION
Avatar of JoshdanG
JoshdanG

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer