I’m having a stupid problem here. It’s not such a big deal, but as I have it almost every day, I’m looking for a workaround.
I’m dealing on a project which as roughtly 250 tables. I quite often need to see the list of those, but when I launch “show tables;”, MySQL outputs it 1 column per line.
Here is a quick sample :
| contact |
| content_footer |
| content_footer_translation |
| content_homepage |
| content_homepage_image |
| content_homepage_translation |
What I would like is to be able to display it in n columns by defining n myself, or even better, n should be calculated in a way so that the line width won’t excess X characters.
Expected output:
| contact | content_footer | content_footer_translation |
| content_homepage | content_homepage_image | content_homepage_translation |
I’m not sure it’s really possible to do that purely in MySQL, but if you know a nice one-liner which can do that in Bash, it’s fine too 🙂
Try this:
This will combine the names to lines of suitable length. You can adjust the line length using the
-wflag tofmt. It won’t form new columns, though.A solution which does build columns is the following one:
It is written in five lines for readability, although you can of course write it in a single logical line with semicolons. If you want to adjust the number of columns, you’ll have to do so in five places: the number of empty strings, the loop test, the format string, the printf arguments and the shift argument. If you want to adjust the column widths, you’ll have to do so repeatedly in the format string. No automatic computation involved.