up vote 1 down vote favorite
share [g+] share [fb]

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

link|improve this question

69% accept rate
1  
This looks to be a programming question. You might be more likely to get an answer on Stack Overflow – Martin Hilton Feb 22 '10 at 6:50
feedback

3 Answers

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
link|improve this answer
feedback

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)

link|improve this answer
The GNUWin32 project is a better (more updated, based on GNU tools) collection of Unix tools for Windows. – dolmen Mar 26 '11 at 16:12
feedback

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.

link|improve this answer
It also takes a second to start up and is way overkill for this. – Joey Mar 26 '11 at 17:20
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.