Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
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

3 Answers 3

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
share|improve this answer

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)

share|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

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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