saída do mysql é delimitada por tabulações. column
substitui tabulações por espaços que quebram sua entrada.
#!/bin/bash
while read -r output;
do
# use double quotes with "$output" to avoid conversion
# of tabs to spaces and set awk's Field Separator to "\t"
echo "$output" | awk -F"\t" '{print $4}'
#do something
done< <(mysql -u root -ptoor super_market -h 0 -e "select * from items;" | sed 1d)
teste executado:
root@c2:~# mysql -u root -ptoor super_market -h 0 -e "select * from items;"
+---------+------------+--------+-------------+-------+
| item_id | item_name | weight | brand | price |
+---------+------------+--------+-------------+-------+
| 1 | Milk | 2 | Nestle | 2 |
| 2 | Cheese | 2.5 | Amul | 6 |
| 3 | Chips | 25 | Lays | 3 |
| 4 | Coke | 5 | Coke Cola | 3.5 |
| 5 | Engage | 5 | Deo | 3.5 |
| 6 | Engage | 5 | Deo | 3.5 |
| 7 | Ear phones | 4 | Skull Candy | 32.3 |
+---------+------------+--------+-------------+-------+
root@c2:~# ./test.sh
Nestle
Amul
Lays
Coke Cola
Deo
Deo
Skull Candy
root@c2:~#