0

I have a set of *.sql files (>2000) which contain table creation scripts per file. My goal is to write all of the sql files to one table. I want to accomplish this by creating the table before reading and writing the files. Each file I read I want to filter to only contain the INSERT INTO lines.

I currently read the files as follows: with open(file) as f: sql = f.read()

This returns a string which holds the table creation string as well as the INSERT statements. Is there any simple string filtering way to only return the lines containing the INSERT statements?

inneb
  • 1,060
  • 1
  • 9
  • 20
  • Adding an example of the file contents(as text) to the question would go a long way to helping format an answer. A guess would be to use `readline()` and look for lines that start with `INSERT`. – Adrian Klaver Jan 11 '23 at 16:53

0 Answers0