Last active
September 15, 2015 13:58
-
-
Save troelskn/f76e42de0c92d12fc1fb to your computer and use it in GitHub Desktop.
On mac osx, turn a mysql console result into something that can be pasted into excel
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
#!/usr/bin/env ruby | |
# put in /usr/local/bin/mysql2excel | |
buffer = [] | |
input = `pbpaste`.strip | |
input.split("\n").each do |line| | |
unless line =~ /^([+-]+|\d+ rows in set.*|mysql>)$/ | |
buffer << line.gsub(/^[|]/, "").gsub(/[|]$/, "").strip.gsub(/\s*[|]\s*/, "\t") | |
end | |
end | |
IO.popen "pbcopy", "w" do |pipe| | |
pipe.puts buffer.join("\n") | |
end | |
puts "Copied to clipboard" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment