Rearranging text in a file

Score
0
Vote Up
January 9, 2012 at 02:11:40 Pacific
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


Reply ↓  Report •


#1
Vote Down
Score
0
Vote Up
January 9, 2012 at 13:09:52 Pacific

Post your script.


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


Reply ↓  Report •

#2
Vote Down
Score
0
Vote Up
January 9, 2012 at 21:01:47 Pacific

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
)


Reply ↓  Report •

#3
Vote Down
Score
0
Vote Up
January 9, 2012 at 22:28:50 Pacific

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.


Reply ↓  Report •

#4
Vote Down
Score
0
Vote Up
January 9, 2012 at 23:18:12 Pacific

yes, many more. is there a way to accomplish this task without using tokens?

Reply ↓  Report •

Related Posts

#5
Vote Down
Score
0
Vote Up
January 10, 2012 at 22:31:02 Pacific

can some please help? i need a way to do this, fairly urgently

Reply ↓  Report •

#6
Vote Down
Score
0
Vote Up
February 5, 2012 at 14:05:35 Pacific

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.


Reply ↓  Report •

Reply to Message Icon Start New Discussion
« help on SQL query A VBScript UAC Problem »

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.

Ask the Community!
Describe your Problem
Example: Hard Drive Not Detected on My PC