Skip to content

Instantly share code, notes, and snippets.

@troelskn
Last active September 15, 2015 13:58
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 troelskn/f76e42de0c92d12fc1fb to your computer and use it in GitHub Desktop.
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
#!/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