Copy multiple words into new text file

November 3, 2010 at 15:38:02
Specs: Windows XP
How would you code a .bat file to copy the following text in "abc.txt" to "def.txt" and format as listed below?

abc.txt
---------
WorldWorldWorld

def.txt
---------
World
World
World

Thanks in advance for your help.


See More: Copy multiple words into new text file

Report •


#1
November 3, 2010 at 16:17:05
It's one thing to break a string like WorldWorldWorld into three lines.

To generalize it, you need to define the breakup criteria.


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 4, 2010 at 05:34:58
For this example, let's say break up criteria would be every 5th character parse it and send it to a new line.

Thanks.


Report •

#3
November 4, 2010 at 08:24:03
Untested VBScript:
With CreateObject("Scripting.FileSystemObject")
  Set inFile = .OpenTextFile("abc.txt")
  Set outFile = .OpenTextFile("def.txt", 2, True)
End With
Do Until inFile.AtEndOfStream
  outFile.WriteLine inFile.Read(5)
Loop

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
November 4, 2010 at 08:27:31
@echo off > def.txt & setLocal enableDELAYedeXpansion

set N=

for /f "tokens=* delims= " %%a in (abc.txt) do (
set S=%%a
for /L %%i in (0 5 50) do (
  if '!S:~%%i^,5!' neq '' (
    set /a N+=1
    set V!N!=!S:~%%i,5!
  )
)
)

for /L %%n in (1 1 !N!) do (
>> def.txt echo.!V%%n!
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
November 4, 2010 at 09:48:39
Amazing, thank you so much Mechanix!

Report •

#6
November 4, 2010 at 11:22:02
Mechanix, it worked but I'm interested in learning about the code, any comments you could provide about the code would be appreciated if you had a few minutes.

Thanks again.


Report •

#7
November 4, 2010 at 13:48:20
For each lline in the file it sets the line to var S.

It increments a counter N.

Sets var VN to first 5 chars.

Sets var to next 5 if not empty.

After settings vars to "words" for each line in file, sends them each on their own line to new file.


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
November 8, 2010 at 14:55:32
Thank you M2, much appreciated!

Report •

#9
November 8, 2010 at 15:17:40
I'm working on one which doesn't need to be told the word length.


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question