title: Batch Files: How to concatenate each line in a text file?
body: <p>I have a text file with text on each line. I would like to be able to put each line in one long line along with a space. So, if the text file has:</p>
  
  <pre><code>Bob
  Jack
  Sam
  </code></pre>
  
  <p>I want the result to be </p>
  
  <pre><code>Bob Jack Sam
  </code></pre>
  
  <p>Below are two methods that I am working on but I am stuck. Anything in brackets [] means that I know the syntax is completely wrong; I only put it there to show my thought process. The commented sections are just me experimenting and I have left them in case anyone wants to comment on what they would do / why they do what they do.</p>
  
  <p>Method 1:</p>
  
  <pre><code>@echo off
  SETLOCAL EnableDelayedExpansion
  SET count=1
  FOR /F "tokens=* delims= usebackq" %%x IN ("afile.txt") DO (
  SET var!count!=%%x
  for %%a in (!count!) do (
  !var%%a! = !var%%a! &amp; " "
  echo !var%%a!
  )
  SET /a count=!count!+1
  echo !count!
  )
  
  ::echo !var1! !var2! !var3!
  start "" firefox.exe !var%%a!-1
  
  ENDLOCAL
  
  ::echo "endlocal" %var1% %var2% %var3%
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>@echo off
  SETLOCAL EnableDelayedExpansion
  SET count=1
  FOR /F "tokens=* delims= usebackq" %%x IN ("afile.txt") DO (
  SET var!count!=%%x
  call echo %%var!count!%%
  
  SET /a count=!count!+1
  echo !count!
  )
  
  ::echo !var1! !var2! !var3!
  start "" firefox.exe ^
  [i = 1]
  [for i to !count! do (]
  call echo %%var!count!%% &amp; " " &amp; " "^
  
  ENDLOCAL
  
  ::echo "endlocal" %var1% %var2% %var3%
  </code></pre>