Rearranging text in a file

January 9, 2012 at 02:11:40
Specs: Windows 7
I'm basically trying to create a batch file that will read a text document and then send each word to a new document with a new line for each word.
Every time i try to do this though, it works until it gets to the 31st word and then repeats that word continuously. Is this a limitation of the batch language or am i doing something wrong?

Thanks for any help


See More: Rearranging text in a file

Report •


#1
January 9, 2012 at 13:09:52
Post your script.


Please come back & tell us if your problem is resolved.


Report •

#2
January 9, 2012 at 21:01:47
Okay, originally i used a for statement with an increasing tokens value but when that didn't work i moved on to this (sorry that it is very messy code):

set y=0
setlocal enabledelayedexpansion
:line
if !y!==0 (
for /f "delims=" %%a in (c:\users\name\desktop\input.txt) do (set line=%%a)
) ELSE (
for /f "skip=%y% delims=" %%a in (c:\users\name\desktop\input.txt) do (set line=%%a)
)
:word
for /f "tokens=1" %%w in ("!line!") do (set word=%%w)
echo !word!>>%cd%\dictionary.txt
for /f "tokens=1*" %%b in ("!line!") do (set line=%%c)
if !line!¶==¶ (
set /a y=!y!+1 && goto line
) ELSE (
goto word
)


Report •

#3
January 9, 2012 at 22:28:50
it works until it gets to the 31st word ..... Is this a limitation of the batch language

Yes, the maximum number of tokens in any For loop is 31.

Does the input text file contain lines with more than 31 words?


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
January 9, 2012 at 23:18:12
yes, many more. is there a way to accomplish this task without using tokens?

Report •

#5
January 10, 2012 at 22:31:02
can some please help? i need a way to do this, fairly urgently

Report •

#6
February 5, 2012 at 14:05:35
As-is, doesn't preserve exclamation points, nor double quotes:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "tokens=* delims=" %%A IN (c:\users\name\desktop\input.txt) DO (
    SET line=%%A
    SET line=!line:"=!
    FOR %%B IN (!line!) DO (
        >>"%cd%\dictionary.txt" ECHO.%%B
    )
)
EXIT /B

When your only tool is a hammer, every problem looks like a nail.


Report •


Ask Question