Difference between revisions of "Crudini"
From Christoph's Personal Wiki
(New page: '''<tt>crudini</tt>''' 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 u...) |
|||
Line 16: | Line 16: | ||
$ crudini --set foobar.conf host foo baz | $ crudini --set foobar.conf host foo baz | ||
$ crudini --get foobar.conf host foo #=> baz | $ crudini --get foobar.conf host foo #=> baz | ||
+ | |||
+ | Note that you can, of course, accomplish the same CRUD tasks as <code>`crudini`</code> 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== | ==External links== |
Latest revision as of 17:53, 27 October 2015
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]