Created
March 22, 2012 18:21
-
-
Save brianwebb01/2161318 to your computer and use it in GitHub Desktop.
Regex to run on the output of $mysql> describe {table}; to get each column's data for some other use... maybe code generation. (remove first 3 lines of mysql output)
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
data = <<EODATA | |
| id | int(11) | NO | PRI | NULL | auto_increment | | |
| physical_address | varchar(255) | YES | | NULL | | | |
| physical_address2 | varchar(255) | YES | | NULL | | | |
| physical_city | varchar(255) | YES | | NULL | | | |
| physical_state_id | int(11) | YES | | NULL | | | |
| physical_postal_code | varchar(255) | YES | | NULL | | | |
| physical_country_id | int(11) | YES | | NULL | | | |
| billing_address | varchar(255) | YES | | NULL | | | |
| billing_address2 | varchar(255) | YES | | NULL | | | |
| billing_city | varchar(255) | YES | | NULL | | | |
| billing_state_id | int(11) | YES | | NULL | | | |
| billing_postal_code | varchar(255) | YES | | NULL | | | |
| billing_country_id | int(11) | YES | | NULL | | | |
+-----------------------------+--------------+------+-----+---------+----------------+ | |
EODATA | |
results = data.scan(/^\|{1}\s{1}(\w+)\s+\|{1}\s{1}(\w+\(?\d*\)?)\s+\|{1}\s{1}(\w+)\s+\|{1}\s{1}(\w*)\s+\|{1}\s{1}(\w+)\s+\|{1}\s{1}(\w*)\s+\|{1}/i) | |
results.each do |match| | |
puts "-"*25 | |
puts match.join(" -- ") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment