Query Contacts database from shell

The contacts are stored in an evolution database (I have some 300 imported from my Ubuntu mobile phone). Is there a way to query and search the database with shell commands?

Update: It’s clear, one can list all entries or export any given entry with commands like:

$ syncevolution --print-items backend=evolution-contacts
pas-id-003a7ecd630a4a3c2512451993373431629b33c1: Buch Kempter
pas-id-008185d4dc4f44de08787eeed512d778f8be3fbe: Gasthaus-zur Post
pas-id-01b7d739a1bb7786745f4a466563af0db255e608: Dolce e Salato
pas-id-036a4f66e622d91113d36a1e3331f64c1c20f3c0: Fynnus Bakenberg

but this is not searching

How about

syncevolution --print-items backend=evolution-contacts | grep 'Fynnus'
?

This gives, ofcourse:

$ syncevolution --print-items backend=evolution-contacts | grep 'Fynnus'
pas-id-036a4f66e622d91113d36a1e3331f64c1c20f3c0: Fynnus Bakenberg

But this is not a real search for any item in all VCF entries.

Seems like a fair question. I would be interested too if someone works this out.

One workaround might be syncevolution --export ... and then use the resulting data in whatever way gets you the functionality you need i.e. in some other “database”. Whether that is reasonable depends on how dynamic your list of contacts is. If you imported 300 initially but now only add 0 or 1 or 2 new contacts a day, it might be OK.

(I used syncevolution --import ... via the Librem 5 “goodies” package to do my import initially. I haven’t tried --export though.)

The database is a SQLite database so take your pick on SQLite clients for querying. The format of the database doesn’t really lend itself too well to being searched directly, depending on what information you need exactly, “given_name” and “family_name” are probably the only useful columns for searching but you might be able to get what you need by doing a “LIKE” match on the vcard column.

For example (using the sqlite3 command line client)…

sqlite3 ~/.local/share/evolution/addressbook/system/contacts.db "SELECT vcard FROM folder_id WHERE vcard LIKE '%FN:Fynnus%'"
2 Likes