hmmm, took a bit of a relook, then i got mad at the interpreter for misinterpreting me and had a long argument with this box.
We aggreed quickly that you got NONE of your blank lines reproduced. FOR by design will skip all blank lines as per "FOR /?" The 2 blank lines you see may have nonprintable characters or multiple spaces, or were non blank lines modified to become blank somewhere in your process.
We also aggreed quickly that you can filter your lines without a FINDSTR command.
It took a very little coaxing for me to convince this box there should be a way to number the lines in a filterable way so FOR doesn't skip them. I ended back up with FINDSTR, but this time telling the PC NOT to use it as a filter, but as a line modifier, letting FOR filter out what I added.
The bigger argument was over symantecs of which of the three basic questions to ask first:
Is line blank?
Is line Special (page break?)
Is line normal?
And this thing about lost the right to exist when it complained out of the blue about some Drive not being found when it should have said it can't handle two adjacent null label lines inside an IF clause, but that's another thread.
Anyway, we came up with the thing below that preserves blank lines and odd lines and removes the first column only from lines that begin with space. Caviat: Lines with 2 or more spaces and nothing else are reduced to blank lines.
If your file start each collumn with something else, then you can adjust the bad character.
If you may have a few different characters there, you must add if clauses for each, OR fix the special case to some first and assume all else can be chopped.
- Enjoy,
2K
(\o/)
:: 2K_Does_Delete_Column_One_
@echo off
if "%1"=="" goto usage_err
if not exist %1 goto usage_err
If exist output.dat del output.dat > nul
set filein=%1
:: first char after quote is the one lines MUST start with to be shifted
set BadCharNoBiscuit=" "
set BadCharNoBiscuit=%BadCharN
:: that could have been done in one line, but wouldn't look readable
:: For skips blank lines
:: line numbers from FINDSTR makes all lines non-blank
for /f "delims=: tokens=1,*" %%j in ('findstr /N "^.*$" %filein%') do (
set fileline=%%k
call :process
)
Echo Done!!!
set fileline=
set zln=
goto exit
:process
:: first word K prevents blank line problem in FOR loop change 1 here to the number of columns to nuke but only the first is checked.
set zln=K %fileline:~1%
:: What type of line is it?
if "%fileline%"=="" (
:: Blank line
echo. >>output.dat
) else if "%fileline:~0,1%"=="%BadCh
:: read tokens to see if there is a word in the line
for /f "tokens=1,*" %%j in ('echo %zln%') do (
if "%%k"=="" (
:: no first word found
echo. >>output.dat
) else (
:: echo will work but use line, not tokens
echo %zln:~2% >>output.dat
)
)
) else (
:: assume page break or all text needed if not space
echo no space at start of ^|%fileline%
echo %fileline% >>output.dat
)
goto EOF
:usage_err
echo usage: %0 filename
:exit
:EOF
Main Topics
Browse All Topics





by: K_2KPosted on 2003-06-19 at 20:19:23ID: 8763314
Hi johanzn,
a few ideas, several questions:
First of all, I'm not feeling the purpose of the findstr in
:process
echo "%fileline%" | findstr >> Nul
if %Errorlevel%==0 goto found
if %Errorlevel%==1 goto Not_Found
My XP gives me nothing but command line error on the findstr line. This one:
echo "%fileline%" | findstr "." >Nul
Always passes, but doesn't seem to notice the difference between a space, blank line, and a Form Feed. That is, :Not_Found never runs. Is your Page Break something other than 0xC (FF)? Can you search specifically for <Your Page Break> && goto :Not_found (maybe change it's name to :PageBreak?)
Also, it seems you're using zln to correctly represent all but the first column of all normal lines, yet echoing the original lines back to output.dat. maybe
@echo %fileline% >> output.dat
could become
@echo %zln% >> output.dat
except i had some lines in my file that had spaces in it but nothing else. That caused the line to change to:
ECHO is off.
Using another FOR /F . . . to find if there is not a first word may be a better way to choose :blankline.
Let us know what you come up with, or tell us what your page break looks like so maybe we can help choose the loop to call from within the FOR /F and avoid some of the other problems altogether.
Good Luck,
2K
(\o/)