Windows package: how to remove all empty (or empty) lines

I am trying to remove all empty lines from a text file using a Windows batch program.

I know that the easiest way to achieve this is ba sh through regular expressions and sed command:

sed -i "/^$/d" test.txt

Question: Does the Windows package have a similar simple way to delete all lines from a text file? Otherwise, what is the easiest method to achieve this?

Note: I am running this script package to install new Windows computers for use by clients, so it is advisable that no additional programs are installed (and then configured) to achieve this - Ideally, I just use the "standard" batch library.

+4
source share
1 answer

For / f does not handle empty lines:

for /f "usebackq tokens=* delims=" %%a in ("test.txt") do (echo(%%a)>>~.txt
move /y  ~.txt "test.txt"
+4
source

Source: https://habr.com/ru/post/1625307/


All Articles