A simple CSV-based key/value storage
#!/bin/bash
# Use with `source db.sh`
touch db.csv
db () {
case $1 in
put)
key=$2
value=$3
gsed -ribak "/^$key\t/d" db.csv
gecho -e "$key\t$value" >>"db.csv"
;;
get)
key=$2
ggrep -Pie "^$key\t" "db.csv" | cut -f2
;;
remove|rm)
key=$2
gsed -ribak "/^$key\t/d" db.csv
;;
list)
cat db.csv | sort
;;
truncate)
mv db.csv db.csvbak
touch db.csv
;;
*)
gecho "Unrecognized command!"
;;
esac
}