Solved Remove lines starting with a space, including empty lines

April 17, 2013 at 05:22:57
Specs: Windows 7
To delete the lines of a txt file that begins with a space (including empty lines), I write

findstr /v /b /c:" " <%1>result.out.
Indeed, result.out file get answer for me if there is no longer both space at beginning of every line and empty line.

What I have done still leaving lines header empty, it also preserves blank lines what i want to give up. Finally, the result.out output must have consecutive lines always containing a text at begining of each line.

Please someone could tell me what it is faulty and how to fix that?

See More: Remove lines starting with a space, including empty lines

Report •

April 17, 2013 at 07:19:22
✔ Best Answer
@echo off & setlocal EnableDelayedExpansion
for /F "delims=" %%i in (%1) do (
  set row=%%i
  if not "!row:~0,1!"==" " echo.%%i>> result.out

Report •

April 17, 2013 at 18:51:14
and you might be able to use tokens, like this:
(for /f "tokens=*" %%a in (myfile) do if "%%a" neq "" echo %%a)>myfile2

Report •

April 18, 2013 at 01:53:12

For /F natively strips away blank lines produced by CR/LF so your statement is useless. Sometime this behavior of For /F may be a problem parsing a text file when you want to retain blank lines.

Report •

Related Solutions

April 18, 2013 at 17:31:05
Yes, you're right. Wasn't thing straight. You'd think "they" would have put a switch, similar to "skip=", that would have let you keep the blanks. That would have been obvious to me. Oh well, I figure batch is on the chopping block in favor of powershell.

Report •

Ask Question