 <pre><code>setlocal enabledelayedexpansion for /l %%b in (1,1,%num%) do echo !line%%b!&gt;&gt;file.txt </code></pre> <p>Or if you don't want to use delayed expansion:</p> <pre><code>for /l %%b in (1,1,%num%) do echo %%line%%b%%&gt;&gt;file.txt </code></pre>