mysql脚本的格式问题_Bash脚本中的Mysql输出格式

我正在写一个bash脚本,我在那个脚本中使用mysql查询,我得到的格式是完全不同的.

查询:

root@debian:~# mysql -u root -ptoor super_market -h 0 -e "select * from items;"

+---------+------------+--------+-------------+-------+

| item_id | item_name | weight | brand | price |

+---------+------------+--------+-------------+-------+

| 1 | Milk | 2.00 | Nestle | 2.00 |

| 2 | Cheese | 2.50 | Amul | 6.00 |

| 3 | Chips | 25.00 | Lays | 3.00 |

| 4 | Coke | 5.00 | Coke Cola | 3.50 |

| 5 | Engage | 5.00 | Deo | 3.50 |

| 6 | Engage | 5.00 | Deo | 3.50 |

| 7 | Ear phones | 4.00 | Skull Candy | 32.30 |

+---------+------------+--------+-------------+-------+

使用column -t命令格式化输出格式

root@debian:~# mysql -u root -ptoor super_market -h 0 -e "select * from items;" | column -t

item_id item_name weight brand price

1 Milk 2.00 Nestle 2.00

2 Cheese 2.50 Amul 6.00

3 Chips 25.00 Lays 3.00

4 Coke 5.00 Coke Cola 3.50

5 Engage 5.00 Deo 3.50

6 Engage 5.00 Deo 3.50

7 Ear phones 4.00 Skull Candy 32.30

Bash脚本

我尝试使用上面的命令的bash脚本

root@debian:~# cat test

#!/bin/bash

while read -r output;

do

echo $output | awk '{print $4}'

#do something

done<

产量

root@debian:~# ./test

Nestle

Amul

Lays

Coke

Deo

Deo

4.00

但预期产出:

Nestle

Amul

Lays

Coke Cola

Deo

Deo

Skull Candy

是啊!你可以说从商品中选择品牌.这是例如实时我使用完全不同的命令.

任何提示或帮助?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值