How to enable tabular output when reading command from file?

How to enable tabular output when reading command from file?

am 16.10.2011 18:36:30 von PengYu.UT

Hi,

~/linux/test/mysql/mysql/SELECT$ ./main.sh
name date type remark
Fluffy 1995-05-15 litter 4 kittens, 3 female, 1 male
Buffy 1993-06-23 litter 5 puppies, 2 female, 3 male
Buffy 1994-06-19 litter 3 puppies, 3 female
Chirpy 1999-03-21 vet needed beak straightened
Slim 1997-08-03 vet broken rib
Bowser 1991-10-12 kennel
Fang 1991-10-12 kennel
Fang 1998-08-28 birthday Gave him a new chew toy
Claws 1998-03-17 birthday Gave him a new flea collar
Whistler 1998-12-09 birthday First birthday
~/linux/test/mysql/mysql/SELECT$ cat main.sh
^[#!/usr/bin/env bash

mysql -hlocalhost -uuser < main.sql

~/linux/test/mysql/mysql/SELECT$ cat main.sql
use test
select * from event;

===============

The above command doesn't print as formatted in the following. I'm
wondering what options I should use to produce a result similar to the
following.


=====================
mysql> select * from event
-> ;
+----------+------------+----------+------------------------ -----+
| name | date | type | remark |
+----------+------------+----------+------------------------ -----+
| Fluffy | 1995-05-15 | litter | 4 kittens, 3 female, 1 male |
| Buffy | 1993-06-23 | litter | 5 puppies, 2 female, 3 male |
| Buffy | 1994-06-19 | litter | 3 puppies, 3 female |
| Chirpy | 1999-03-21 | vet | needed beak straightened |
| Slim | 1997-08-03 | vet | broken rib |
| Bowser | 1991-10-12 | kennel | |
| Fang | 1991-10-12 | kennel | |
| Fang | 1998-08-28 | birthday | Gave him a new chew toy |
| Claws | 1998-03-17 | birthday | Gave him a new flea collar |
| Whistler | 1998-12-09 | birthday | First birthday |
+----------+------------+----------+------------------------ -----+
10 rows in set (0.03 sec)


--
Regards,
Peng

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: How to enable tabular output when reading command from file?

am 17.10.2011 04:57:42 von Dan Nelson

In the last episode (Oct 16), Peng Yu said:
> Hi,
>
> ~/linux/test/mysql/mysql/SELECT$ ./main.sh
> name date type remark
> Fluffy 1995-05-15 litter 4 kittens, 3 female, 1 male
> Buffy 1993-06-23 litter 5 puppies, 2 female, 3 male
> Buffy 1994-06-19 litter 3 puppies, 3 female
> Chirpy 1999-03-21 vet needed beak straightened
> Slim 1997-08-03 vet broken rib
> Bowser 1991-10-12 kennel
> Fang 1991-10-12 kennel
> Fang 1998-08-28 birthday Gave him a new chew toy
> Claws 1998-03-17 birthday Gave him a new flea collar
> Whistler 1998-12-09 birthday First birthday
> ~/linux/test/mysql/mysql/SELECT$ cat main.sh
> ^[#!/usr/bin/env bash
>
> mysql -hlocalhost -uuser < main.sql
>
> ~/linux/test/mysql/mysql/SELECT$ cat main.sql
> use test
> select * from event;
>
> ===============
>
> The above command doesn't print as formatted in the following. I'm
> wondering what options I should use to produce a result similar to the
> following.

Add the --table option to your mysql commandline. In batch mode, mysql
generates tab-delimited output which is easier to process.

o --table, -t

Display output in table format. This is the default for interactive
use, but can be used to produce table output in batch mode.

--
Dan Nelson
dnelson@allantgroup.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org