Created
February 25, 2020 12:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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