0

I get the feeling this is a pretty simple issue but I'm relatively inexperienced with Windows command line hence the need to ask. In a batch file I'm writing, how would I loop through every separate word in a text file, and output that word to a new line in a new text file?

Thanks for any suggestions!

Deacon
  • 1
  • 1

1 Answers1

1

sounds like the uber-flexible and least-known-in-DOS FOR command is what you need something like:

FOR /f %%A in ('dir /b my_dir\*.csv ^| find /V "summary"') do (
rem do here what you want
)

see this stack question

EDIT: This shoudl work foe lines in a file. Eaither way... take a look at for. BTW MUCH easier in Powershell.

for /f "tokens=* delims= " %%a in (myfile) do (
echo do my commands on %%a
)
Community
  • 1
  • 1
penderi
  • 8,673
  • 5
  • 45
  • 62
  • Wouldn't this be doing it for all files in a directory though? I only want to do it for one .txt file, and output to another – Deacon Aug 04 '11 at 08:26
  • Ah remiss of me - easy in Pwoershell. Is that ok or just DOS ?? – penderi Aug 04 '11 at 08:35
  • I'm trying to do it in just DOS if possible. So far I have this: FOR /F "tokens=*" %%G IN (file1.txt) DO ECHO %%G >> file2.txt – Deacon Aug 04 '11 at 08:37
  • Hmm you look to be quite close.. did the above help ?? I'll take a look. – penderi Aug 04 '11 at 08:37
  • Yeah I've just tried it...it just removes any blank lines in the txt and outputs the rest as before (ie. not one word per line) – Deacon Aug 04 '11 at 08:49