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
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityThere 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
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
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)
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.