Text Processing in Python

Python is an excellent tool for scanning and manipulating textual data.

Example: Strip lines from certain files in a folder

import os
import glob
import shutil
 
path = 'C:\\data'

for aFile in glob.glob( os.path.join(path, '*.sql') ):
	print ("current file is: " + aFile)
	
	shutil.move( aFile, aFile + "~" )
	destination = open( aFile, "w" )
	source = open( aFile+"~", "r" )
	for line in source:
		if not '/****** Object:' in line: 
		   destination.write( line )
		   
	source.close()
	destination.close()