Code snippet to fetch column names between select and from keyword to analyse.
def analyse file_path | |
file = File.open(file_path, "r") | |
counter = 0 # counter for having a 2D Array | |
writefile = false | |
array = Array.new | |
file.readlines.each do |line| | |
if line.start_with? "SELECT" | |
writefile = true; | |
array[counter] = Array.new | |
end | |
if line.start_with? "FROM" | |
writefile = false; | |
counter = counter + 1 | |
end | |
array[counter].push line.strip if writefile == true | |
end | |
require 'csv' | |
CSV.open('.\working_output_analysis.csv', 'w+') do |csv| | |
array.each { |ar| csv << ar } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment