Crudini

From Christoph's Personal Wiki
Revision as of 17:53, 27 October 2015 by Christoph (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

crudini is a utility to simplify reading and updating ini/conf files from shell scripts, so named as it provides CRUD (Create/Read/Update/Delete) functionality.

Example usage

  • Create a test conf file:
$ cat << EOF > foobar.conf
[host]
foo=bar
ip=10.0.0.2
EOF
  • Get the value of a given key:
$ crudini --get foobar.conf host ip #=> 10.0.0.2
  • Change the value of a given key:
$ crudini --get foobar.conf host foo #=> bar
$ crudini --set foobar.conf host foo baz
$ crudini --get foobar.conf host foo #=> baz

Note that you can, of course, accomplish the same CRUD tasks as `crudini` using awk:

$ cat << EOF >foobar.conf
[foo]
[bar]
[baz]
EOF
$ echo -e 'one\ntwo' | awk '{ print } $1 == "[bar]" && c == 0 { c = 1; system("cat") }' foobar.conf 
[foo]
[bar]
one
two
[baz]

External links