Reputation: 51
Thanks in advance for your valuable inputs
Through a batch
file,I'm trying to read line by line a text file
except those starting with space.
I have tried this:
for /f "eol=^"" " %%x in (file.txt) do echo. %%x>out What I have done is also reading lines from file begining with spaces.
I also tried this: for /f "tokens=*" %%a in ('find /v ^" " %1') do ( echo.%%a pause console output is empty.
Assume that my file looks like this one:
Draw something
******* STEP 1 ********
Draw something else
============================ ...............................
For this example, I have to read one line after another one
Draw something
Draw something else
Any help!!
Upvotes: 0
Views: 420
Reputation: 130819
You found the correct FOR /F option, but you failed to find the correct usage. All lines that begin with the EOL character are skipped, and the very next character after EOL=
is always the EOL character. You simply want a space after the equal.
You also want to preserve the entire line, so you need to set DELIMS to nothing.
for /f "eol= delims=" %%x in (file.txt) do echo. %%x>out
Peter Wright's FINDSTR solution is a simpler way to eliminate lines that begin with space. But I'm assuming you want to do additional processing with each line that does not begin with space.
Upvotes: 0
Reputation: 80023
Oh, that's an easy one!
findstr /v /b /c:" " <file.txt
finds lines EXCEPT /v
begin with /b
the literal string " "
/c:" "
see findstr /?
from the prompt for docco...
Upvotes: 1