Skip to content

Instantly share code, notes, and snippets.

@sudiptamondal
Created February 25, 2020 12:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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