title: Add comma to the end of each line of a file using Windows batch file
body: <p>I have a batch file that looks in several .RTF files (file1) for specific info then puts the name of the document in file2.  I need to create a comma delimited file (file3) to use in a command line email program to send all the file1's as attachments based on the contents of file2.</p>
  
  <p>The batch file I have creates all file1 and file2 correctly. I have a FOR statement that adds a comma to the end of the document names in file2 and it displays the document name with comma when issuing the ECHO command.</p>
  
  <p>The batch file will output only the last document name/comma it encounters to file3.</p>
  
  <p>How can I get all of the document names in file2 to written to file3 with a comma at the end of each line.</p>
  
  <p>Current output to file3:  </p>
  
  <pre><code>7868685425587963.rtf,
  </code></pre>
  
  <p>Desired output to file3:</p>
  
  <pre><code>7868684496427836.RTF,
  786868535408221.RTF,
  7868685416423800.RTF,
  7868685425587963.rtf,
  </code></pre>
  
  <p>Script in batch file:</p>
  
  <pre><code>setlocal
  
  del file2.txt
  del file3.txt
  
  set comma=,
  echo %comma%
  
  rename *.DAT *.RTF,
  
  findstr /m "0097" *.RTF &gt;&gt; file2.txt 
  
  for /f  %%a In (file2.txt) DO set str=%%a%comma%  
  echo %str%&gt;&gt; file3.txt
  
  pause
  
  endlocal
  </code></pre>
  
  <p>command line output:<br>
  <a href="https://i.stack.imgur.com/nTvpF.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nTvpF.gif" alt="command line output"></a></p>
  
  <p>I've been trying to figure this out off and on for several weeks and have tried many iterations.</p>