title: Translation from Python to Batch for a CSV program
body: <p>I really need help with using a batch file to do the following:</p>
  
  <p>I need to read in a text file line by line and, for each entry of a given CSV file that starts with an element found in the line of text file, write it into a new CSV file.</p>
  
  <p>Or, in other words:</p>
  
  <p>Read the following</p>
  
  <pre><code>example.csv
  Page, Pageviews, Bounce Rate, /category/apples, 1029, 67%, /category/brussel-sprout, 3409, 92%, /category/orange, 1233, 87%
  </code></pre>
  
  <p>Then read the following text file line by line:</p>
  
  <pre><code>example.txt
  /category/apples
  /category/orange
  </code></pre>
  
  <p>And create this file:</p>
  
  <pre><code>new.csv
  Page, Pageviews, Bounce Rate, /category/apples, 1029, 67%, /category/orange, 1233, 87%
  </code></pre>
  
  <p>So far I've worked on this project through a batch file that takes each individual address of a list, checks to see if it has a certain header, and then writes the extension in a list. Unfortunately this isn't enough, as I also need to then regenerate the tables from the original CSV -- but only the ones with a header. I was attempting to do this via Python but it was proving too cumbersome (and system boundaries made it not feasible to write Python, anyway). If you'd like to see code you can click on my questions through my profile, but they don't concern this piece. What I have left to do is this, and I ask for clarity and ideas as my strengths don't lie in BAT but C++ (and no, that's not an option).</p>
  
  <p>Thank you for the help. This community has (with some exception) proved excellent grounds for learning valuable lessons and pushing me to succeed. </p>
  
  <p>This is where I was headed with Python:</p>
  
  <pre><code>import csv
  
  lines = []
  with open('output.txt','r') as f:
      for line in f.readlines():
          lines.append(line[:-1])
  
  with open('corrected.csv','w') as correct:
      writer = csv.writer(correct, dialect = 'excel')
      with open('input.csv', 'r') as mycsv:
          reader = csv.reader(mycsv)
          for row in reader:
              if row[0] not in lines:
                  writer.writerow(row)
  </code></pre>