6

There are unnecessary new lines in txt files which i am merging during batch processing. I am thinking fof first removing all new lines and then inserting only one.

how can i do that in batch file

2

3 Answers 3

9

You can do the same as Idigas's answer (filtering non-empty lines) using the Windows built-in tool findstr:

findstr "." input.txt > output.txt
1

I don't know of a way to do it via cmd, since I always have done it via grep. grep is a part of unixkit-tiny, a rar archive of small tools that came to windows as a port from unix world. Just unrar and use, no installation necessary.

Removing lines:

grep . your_file.txt > your_file_without_empty_lines.txt

(this will copy all non blank lines from your_file.txt to a new file - lines which only have spaces in them are not considered blank)

1
  • The GNUWin32 project is a better (more updated, based on GNU tools) collection of Unix tools for Windows.
    – dolmen
    Mar 26, 2011 at 16:12
-2

You can try PowerShell (just because it'll take less lines).
Read every line in the file and write it to another file UNLESS it contains just the newline character. That way you copy each line with 1 newline character - exactly what you needed.

1
  • 2
    It also takes a second to start up and is way overkill for this.
    – Joey
    Mar 26, 2011 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .