Ngaaa .. talk about daytime headache ...
I had the same problem today ... I need to parse the lines with FOR / F, where each line had a series of sentences (each with embedded spaces, possibly) with each sentence separated by TAB.
My problem is that my coding standards (even for BATCH files) forbid actual TAB characters from source code (our editors forbid putting TAB in and our ctrl Version tools forbid any CheckIn of any text file with TAB or WTR [from white to the right].)
So this is a hack, but it works on XP (hanging head ... deep shame ...)
SET REG_CPU="HKLM\Hardware\Description\System\CentralProcessor\0" REG.EXE QUERY %REG_CPU% /V IDENTIFIER | FIND "REG_SZ" > RegCPUid.Tmp for /F "tokens=2 delims=rR" %%i in (RegCPUid.Tmp) do SET TAB=%%~i
This works on XP, but I have not tested Win7 or Win7 [WoW64].
Temporary contents of RegCPUid.Tmp is ONE LINE that looks like
" IDENTIFIER<tab>REG_SZ<tab>x86 Family 6 Model 37 Stepping 2"
The FOR command simply pulls out a single TAB between the two "R" s IDENTIFIER and REG_SZ and sets the TAB environment variable for it.
Then my script can do the whole FOR / F loop that it wants, ONLY the tab character as a delimiter (and NOT a space) ...
for /F "tokens=1-3* delims=%TAB%" %%i in (Sentences.txt) do ECHO The THIRD sentence is %%k
All this allows me to NOT have any hard-coded TAB characters in the BATCH file.
-dave
source share