Search code examples
bashshellawkscriptingzenity

Populating a zenity list with results from mysql


I'm doing a small project using BASH for a "Phone Book". It stores the data in a mysql database and uses a temporary file to work with the Selects.

I'm using zenity visual interface, so I want to display the data stored in the database using the Zenity List Dialog. For doing that, I need to use the values of the columns individually, so I need to use the awk command to get those, but I'm having trouble in combining both zenity and awk commands.

Storing the values of the database, separated by \t in the temporary file.

echo "SELECT name,address,telephone,email FROM agenda" | mysql projAgenda -N -u root -p12345 >> tempAgenda.dat

Displaying the data using zenity --list

awk -F'\t' '{zenity --list --title="Listar registos" --text="" --column="Name" --column="Address" --column="Telephone" --column="E-mail" $1 $2 $3 $4}' tempAgenda.dat

But I'm always getting the same error:

awk: line 1: syntax error at or near =

Can someone help? I know I might be screwing up really big in trying to mix those two commands, but can't think of doing it another way.

EDIT: Output of the query (separated by tabs):

José Manel  Rua António Cão 219886868   [email protected] 
Cláudio Pinto   Praça Dom Rui da Camara 219886820   [email protected]

Solution

  • You need to replace the tab delimiter returned by mysql with a new line since zenity expects each column to be on a separate line when it reads from stdin. You can use tr for that:

    mysql -N ... | tr '\t' '\n' | zenity --list --title="Listar registos" --text="" --column="Name" --column="Address" --column="Telephone" --column="E-mail" 
    

    This would produce the following list:

    enter image description here