Skip to content

Instantly share code, notes, and snippets.

@sudiptamondal
Created February 25, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudiptamondal/4013f2e2a6ec2da9179437495c978cdc to your computer and use it in GitHub Desktop.
Save sudiptamondal/4013f2e2a6ec2da9179437495c978cdc to your computer and use it in GitHub Desktop.
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