The zeptodb tools are used to create small databases that are stored to disk and then to store, fetch and remove records from those databases. These databases are much simpler than, say, SQL databases, so no queries need to be constructed. The databases follow the DBM format as created by the GDBM library. Each record in a DBM database consists of a key and a value. All keys and values are stored as plain text, regardless of their formats.
First, you create a new database with
$ zdbc foo.db
With the database created, you may now store values to it using
zdbs normally takes its input from
stdin. It expects one record per line and for each key/value
pair to be separated by a delimiter character (’|’ by default). Note
that records are unique: an attempt to store a record with a
pre-existing key will overwrite that record with a new value.
For example, let’s say that you have a text file emails.txt containing the following records:
Brandonfirstname.lastname@example.org Joeemail@example.com Maryfirstname.lastname@example.org
You could store the records in foo.db like so:
$ zdbs foo.db <emails.txt
Note that if you simply don’t like shell redirections like this, you can also use the -i or --input option to specify the input file:
$ zdbs -i emails.txt foo.db
Of course, it’s more likely that you’ll want to pipe in records from some other process:
$ fancy_pipeline.sh | zdbs foo.db
If your records are formatted differently, using, say, ’-’ as the delimiter (i.e "key-value"), you would specify it using the -d or --delimiter option.
Records can then be fetched from the database using
this case, queries in the form of keys with one key per line are read
$ zdbf foo.db Brandon email@example.com Joe firstname.lastname@example.org Jon ../trunk/src/zdbf: Key does not exist in the database: Jon: Invalid argument
zdbs, you can also specify a file containing the
queries using the -i option or you can read them in through a
If you would prefer the output to include the key, you must specify your desired delimiter using the -d option:
$ echo Brandon | zdbf -d':' foo.db Brandon:email@example.com
Finally, you can dump out all of the contents of the database using the -a option. Note that the order of the records is in no way guaranteed.
$ zdbf -d'|' -a foo.db Joefirstname.lastname@example.org Brandonemail@example.com Maryfirstname.lastname@example.org
Records may then be removed from the database using
zdbr operates in a very similar way to
$ zdbr foo.db <<EOF > Brandon > Joe > EOF $ zdbf -a -d'|' foo.db Maryemail@example.com
Of course, these examples are not realistic. Rather than using the programs from the command-line, you are more likely to use them in scripts. For example, one script might save data to a database while another script reads from that data. You can even build up relations between multiple databases, storing the keys of one database as values in another database, allowing quite complex, but always fast, look-ups within your scripts.