<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Processing the contents of a text file using FOR loop</title>
	<atom:link href="http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/</link>
	<description>Computer and technology tutorials and guides</description>
	<lastBuildDate>Sat, 21 Nov 2009 18:18:34 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Tom J</title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-6019</link>
		<dc:creator>Tom J</dc:creator>
		<pubDate>Thu, 11 Dec 2008 10:35:00 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-6019</guid>
		<description>Geza,&lt;br&gt;&lt;br&gt;Very simple&lt;br&gt;here is an example with your requirements&lt;br&gt;&lt;br&gt;For /f %%a in (test.txt) do echo computername = %%a&gt;&gt;result.txt &amp; copy \serverfile \%%ac$folder &amp; net send admin %%a has been updated</description>
		<content:encoded><![CDATA[<p>Geza,</p>
<p>Very simple<br />here is an example with your requirements</p>
<p>For /f %%a in (test.txt) do echo computername = %%a&gt;&gt;result.txt &#038; copy \serverfile \%%ac$folder &#038; net send admin %%a has been updated</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-3409</link>
		<dc:creator></dc:creator>
		<pubDate>Sat, 07 Jul 2007 13:36:43 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-3409</guid>
		<description>Hello again,

Does someone know how to run not one but two or more commands in a FOR loop?

For example here is the example that I used at the begining of this discussion:

For /f %%a in (test.txt) do echo computername = %%a&gt;&gt;result.txt 

where the single command to be executed is &quot;do echo computername = %%a&gt;&gt;result.txt &quot;

But what is the syntax for this?

1. grab the first/next computer name from the text file
2. echo computer name to another text file
3. copy a file from the server to a folder on the same computer
4. net send admin &quot;computer&quot; has been updated

then go back and pick the next computer name from the text file and run the same commands again.

So, the basic question is what is the syntax for running multiple commands with the same variable in a FOR loop?

Geza</description>
		<content:encoded><![CDATA[<p>Hello again,</p>
<p>Does someone know how to run not one but two or more commands in a FOR loop?</p>
<p>For example here is the example that I used at the begining of this discussion:</p>
<p>For /f %%a in (test.txt) do echo computername = %%a&gt;&gt;result.txt </p>
<p>where the single command to be executed is &#8220;do echo computername = %%a&gt;&gt;result.txt &#8221;</p>
<p>But what is the syntax for this?</p>
<p>1. grab the first/next computer name from the text file<br />
2. echo computer name to another text file<br />
3. copy a file from the server to a folder on the same computer<br />
4. net send admin &#8220;computer&#8221; has been updated</p>
<p>then go back and pick the next computer name from the text file and run the same commands again.</p>
<p>So, the basic question is what is the syntax for running multiple commands with the same variable in a FOR loop?</p>
<p>Geza</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-2899</link>
		<dc:creator></dc:creator>
		<pubDate>Tue, 06 Jun 2006 14:14:07 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-2899</guid>
		<description>&lt;strong&gt;WINDOWS 2003&lt;em&gt;(did not test in XP)&lt;/em&gt;&lt;/strong&gt;
The key is to use delimaters...well, sorta.  You want to trick the FOR loop into looking for delimiters.
&lt;strong&gt;~~ SERVICES.TXT ~~&lt;/strong&gt;
&lt;code&gt;; be sure to surround your values by QUOTES &#40;&quot;&#41;
&quot;Apache Tomcat 4.1.31&quot;
&quot;Apache Tomcat 5.0.27&quot;
&quot;MySQL41&quot;
; and with the EOL switch, lines beginning in &quot;;&quot; are ignored
&lt;/code&gt;
&lt;strong&gt;~~ START.EM.UP.BAT ~~&lt;/strong&gt;
&lt;code&gt;FOR /F &quot;eol=; tokens=1,2,3,4,5,6,7* delims= &quot; %%a IN &#40;SERVICES.TXT&#41; DO NET STOP %%a %%b %%c %%d %%e %%f %%g
&lt;/code&gt;
also notice a few things&lt;ul&gt;1. no quotes around filename&lt;/ul&gt;&lt;ul&gt;2. the &quot;%%x&quot; variables have two % symbols (this is because i&#039;m running inside of a BAT already.&lt;/ul&gt;&lt;ul&gt;3. there are just as many &quot;tokens&quot; as there are &quot;%%x&quot; variables&lt;/ul&gt;&lt;ul&gt;4. there is only a space after the &lt;em&gt;delims= &lt;/em&gt; declaration&lt;/ul&gt;
lastly, the resulting output:&lt;code&gt;NET STOP &quot;Apache Tomcat 4.1.31&quot;
NET STOP &quot;Apache Tomcat 5.0.27&quot;
NET STOP &quot;MySQL41&quot;&lt;/code&gt;
PERFECT !!!!!!!!!!!!!!!!!!!!!</description>
		<content:encoded><![CDATA[<p><strong>WINDOWS 2003<em>(did not test in XP)</em></strong><br />
The key is to use delimaters&#8230;well, sorta.  You want to trick the FOR loop into looking for delimiters.<br />
<strong>~~ SERVICES.TXT ~~</strong><br />
<code>; be sure to surround your values by QUOTES &#40;&quot;&#41;<br />
&quot;Apache Tomcat 4.1.31&quot;<br />
&quot;Apache Tomcat 5.0.27&quot;<br />
&quot;MySQL41&quot;<br />
; and with the EOL switch, lines beginning in &quot;;&quot; are ignored<br />
</code><br />
<strong>~~ START.EM.UP.BAT ~~</strong><br />
<code>FOR /F &quot;eol=; tokens=1,2,3,4,5,6,7* delims= &quot; %%a IN &#40;SERVICES.TXT&#41; DO NET STOP %%a %%b %%c %%d %%e %%f %%g<br />
</code><br />
also notice a few things
<ul>1. no quotes around filename</ul>
<ul>2. the &#8220;%%x&#8221; variables have two % symbols (this is because i&#8217;m running inside of a BAT already.</ul>
<ul>3. there are just as many &#8220;tokens&#8221; as there are &#8220;%%x&#8221; variables</ul>
<ul>4. there is only a space after the <em>delims= </em> declaration</ul>
<p>lastly, the resulting output:<code>NET STOP &quot;Apache Tomcat 4.1.31&quot;<br />
NET STOP &quot;Apache Tomcat 5.0.27&quot;<br />
NET STOP &quot;MySQL41&quot;</code><br />
PERFECT !!!!!!!!!!!!!!!!!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-2898</link>
		<dc:creator></dc:creator>
		<pubDate>Tue, 06 Jun 2006 13:43:16 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-2898</guid>
		<description>i&#039;m having the same difficulty.

I&#039;m trying to build a &quot;START ALL THESE SERVICES&quot; type batch file, and my Services.TXT file contains spaces.

I just can&#039;t seem to get the BAT to ignore the spaces.  Has anyone else seen the same problem?

&lt;em&gt;&lt;strong&gt;~~ SERVICES.TXT ~~&lt;/strong&gt;
Apache Tomcat 5.0.27
MySQL 41

&lt;strong&gt;~~ STARTEM.UP.BAT ~~&lt;/strong&gt;
FOR /f %%a in (SERVICES.TXT) do NET START &quot;%%a&quot;&lt;/em&gt;

all it tries to run is:
&lt;em&gt;NET START &quot;Apache&lt;/em&gt;

thanks for the GREAT tip though.
Michael &quot;SPENGLER&quot; Lowden</description>
		<content:encoded><![CDATA[<p>i&#8217;m having the same difficulty.</p>
<p>I&#8217;m trying to build a &#8220;START ALL THESE SERVICES&#8221; type batch file, and my Services.TXT file contains spaces.</p>
<p>I just can&#8217;t seem to get the BAT to ignore the spaces.  Has anyone else seen the same problem?</p>
<p><em><strong>~~ SERVICES.TXT ~~</strong><br />
Apache Tomcat 5.0.27<br />
MySQL 41</p>
<p><strong>~~ STARTEM.UP.BAT ~~</strong><br />
FOR /f %%a in (SERVICES.TXT) do NET START &#8220;%%a&#8221;</em></p>
<p>all it tries to run is:<br />
<em>NET START &#8220;Apache</em></p>
<p>thanks for the GREAT tip though.<br />
Michael &#8220;SPENGLER&#8221; Lowden</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-2790</link>
		<dc:creator></dc:creator>
		<pubDate>Tue, 04 Apr 2006 02:56:08 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-2790</guid>
		<description>the last result is:
Dir &quot;C:Documents

not Dir &quot;C:Documents_and</description>
		<content:encoded><![CDATA[<p>the last result is:<br />
Dir &#8220;C:Documents</p>
<p>not Dir &#8220;C:Documents_and</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-2789</link>
		<dc:creator></dc:creator>
		<pubDate>Tue, 04 Apr 2006 02:54:36 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-2789</guid>
		<description>i tried your ide, and that&#039;s work fine, but....

My source file contain:
C:Documents and Settingsyves
C:Documents and Settingsvalerie
etc..

The batch just do a DIR (finally i would like to make a xcopy)

The result is:
Dir C:Documents

The space between the word Document and the word Settings stop the rest. I tried to use &quot;C:Documents and Settingsyves&quot; and the result was:
Dir &quot;C:Documents_and

So, how to resolv that ??
Thanks, Yves</description>
		<content:encoded><![CDATA[<p>i tried your ide, and that&#8217;s work fine, but&#8230;.</p>
<p>My source file contain:<br />
C:Documents and Settingsyves<br />
C:Documents and Settingsvalerie<br />
etc..</p>
<p>The batch just do a DIR (finally i would like to make a xcopy)</p>
<p>The result is:<br />
Dir C:Documents</p>
<p>The space between the word Document and the word Settings stop the rest. I tried to use &#8220;C:Documents and Settingsyves&#8221; and the result was:<br />
Dir &#8220;C:Documents_and</p>
<p>So, how to resolv that ??<br />
Thanks, Yves</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-1876</link>
		<dc:creator></dc:creator>
		<pubDate>Wed, 18 May 2005 19:30:45 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-1876</guid>
		<description>Well, at least in Windows XP Pro, you do not need to put the filename between quotes (&quot;test.txt&quot;) or (&#039;test.txt&#039;) instead, you just have to use parenthesis like here:

For /f %%a in (test.txt) do echo computername = %%a&gt;&gt;result.txt

Geza</description>
		<content:encoded><![CDATA[<p>Well, at least in Windows XP Pro, you do not need to put the filename between quotes (&#8221;test.txt&#8221;) or (&#8217;test.txt&#8217;) instead, you just have to use parenthesis like here:</p>
<p>For /f %%a in (test.txt) do echo computername = %%a&gt;&gt;result.txt</p>
<p>Geza</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: </title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-1875</link>
		<dc:creator></dc:creator>
		<pubDate>Wed, 18 May 2005 19:21:53 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-1875</guid>
		<description>Hello,

I tried the following line from a batch file, from command line with one and two &quot;%&quot;s, it just doesn&#039;t work.

FOR /f %%a in (&#039;test.txt&#039;) do echo Computer: %%a

(I do have a test.txt file in the same folder that contains 5 server names one below the other, like this:

s02
s03
s04
s05
s06

The only thing it does, that it will actually open the test.txt file and that&#039;s it.
I also tried the script that someone else posted here as a comment, that didn&#039;t work either.

Would some post a whole, complete but simple script for a batch file, that will do  
          echo %%a&gt;&gt;result.txt  ?

Thanks,
Geza</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I tried the following line from a batch file, from command line with one and two &#8220;%&#8221;s, it just doesn&#8217;t work.</p>
<p>FOR /f %%a in (&#8217;test.txt&#8217;) do echo Computer: %%a</p>
<p>(I do have a test.txt file in the same folder that contains 5 server names one below the other, like this:</p>
<p>s02<br />
s03<br />
s04<br />
s05<br />
s06</p>
<p>The only thing it does, that it will actually open the test.txt file and that&#8217;s it.<br />
I also tried the script that someone else posted here as a comment, that didn&#8217;t work either.</p>
<p>Would some post a whole, complete but simple script for a batch file, that will do<br />
          echo %%a&gt;&gt;result.txt  ?</p>
<p>Thanks,<br />
Geza</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jkhax0r</title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-133</link>
		<dc:creator>jkhax0r</dc:creator>
		<pubDate>Tue, 23 Mar 2004 17:27:23 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-133</guid>
		<description>Thanks for the tip on subroutines.  It really helped.</description>
		<content:encoded><![CDATA[<p>Thanks for the tip on subroutines.  It really helped.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jwalker</title>
		<link>http://www.tech-recipes.com/rx/363/processing-the-contents-of-a-text-file-using-for-loop/comment-page-1/#comment-103</link>
		<dc:creator>jwalker</dc:creator>
		<pubDate>Tue, 24 Feb 2004 10:45:09 +0000</pubDate>
		<guid isPermaLink="false">guid-fix-me!#comment-103</guid>
		<description>If you need to run multiple commands against one of the computers in the list, you can structure in the following way (my comments formatted for batch files; change double percents (%%) to single (%) to run on command line:

&lt;strong&gt;FOR /f %%a in (&#039;complist.txt&#039;) do call :MY_SUB %%a
GOTO SUB_DONE&lt;/strong&gt;

&lt;strong&gt;:MY_SUB&lt;/strong&gt;

REM Here, the computer name was passed as a parameter, so it comes in as %1

REM Example - copy a file to the computer
copy myfile.txt \%1c$

REM run this to end the subroutine

&lt;strong&gt;GOTO :EOF&lt;/strong&gt;

&lt;strong&gt;:SUB_DONE&lt;/strong&gt;

REM subroutine is finished, rest of the batch file continues</description>
		<content:encoded><![CDATA[<p>If you need to run multiple commands against one of the computers in the list, you can structure in the following way (my comments formatted for batch files; change double percents (%%) to single (%) to run on command line:</p>
<p><strong>FOR /f %%a in (&#8217;complist.txt&#8217;) do call :MY_SUB %%a<br />
GOTO SUB_DONE</strong></p>
<p><strong>:MY_SUB</strong></p>
<p>REM Here, the computer name was passed as a parameter, so it comes in as %1</p>
<p>REM Example &#8211; copy a file to the computer<br />
copy myfile.txt \%1c$</p>
<p>REM run this to end the subroutine</p>
<p><strong>GOTO :EOF</strong></p>
<p><strong>:SUB_DONE</strong></p>
<p>REM subroutine is finished, rest of the batch file continues</p>
]]></content:encoded>
	</item>
</channel>
</rss>
