Remove lines from a file starting with a space, including empty lines
If you want to include Tab characters as part of the whitespace you want to check, you have to use a batch script. The cmd
console simply makes an annoyed sound at you if you try to Tab or paste a Tab character into the console. But cmd
interprets Tab in a .bat
file no problem.
Put this into a batch file and run it, replacing Space and Tab with an actual space and tab.
findstr /r /v /c:"^[
SpaceTab]" /c:"^$" "%~1" >result.out
The first /c:
checks for whitespace at the beginning of a line. The second /c:
checks for blank lines. Both are omitted with the /v
switch.
new
Updated on June 13, 2022Comments
-
new almost 2 years
To delete all 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? Thanks.
-
rojo about 11 yearsWhat's improper about the job it does?
-
new about 11 yearsWhat 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.
-
-
new about 11 yearsYou're good! so perfect Thank you very much for all. I am new in batch but through the "Stackoverflow" forum, I really understand quite a lot of stuff;) Thank you!
-
rojo about 11 years@new - Excellent. I'm glad it worked for you. If you agree that it's appropriate, please consider marking my answer as accepted.